Commit c4c51888 authored by GitLab Bot's avatar GitLab Bot
Browse files

Add latest changes from gitlab-org/gitlab@master

parent d22f0e3b405e
# frozen_string_literal: true
require 'securerandom'
module Alerting
class ProjectAlertingSetting < ApplicationRecord
belongs_to :project
validates :token, presence: true
attr_encrypted :token,
mode: :per_attribute_iv,
key: Settings.attr_encrypted_db_key_base_truncated,
algorithm: 'aes-256-gcm'
before_validation :ensure_token
def ensure_token
self.token ||= generate_token
def generate_token
......@@ -199,6 +199,7 @@ class Project < ApplicationRecord
has_one :metrics_setting, inverse_of: :project, class_name: 'ProjectMetricsSetting'
has_one :grafana_integration, inverse_of: :project
has_one :project_setting, ->(project) { where_or_create_by(project: project) }, inverse_of: :project
has_one :alerting_setting, inverse_of: :project, class_name: 'Alerting::ProjectAlertingSetting'
# Merge Requests for target project should be removed with it
has_many :merge_requests, foreign_key: 'target_project_id', inverse_of: :target_project
......@@ -332,6 +333,7 @@ class Project < ApplicationRecord
accepts_nested_attributes_for :metrics_setting, update_only: true, allow_destroy: true
accepts_nested_attributes_for :grafana_integration, update_only: true, allow_destroy: true
accepts_nested_attributes_for :prometheus_service, update_only: true
accepts_nested_attributes_for :alerting_setting, update_only: true
delegate :feature_available?, :builds_enabled?, :wiki_enabled?,
:merge_requests_enabled?, :forking_enabled?, :issues_enabled?,
......@@ -6,10 +6,6 @@ type: index, howto
>[Introduced][ee-4642] in [GitLab Premium][eep] 10.6.
NOTE: **Note:**
This feature [is available for free]( to users until March 22nd, 2020.
GitLab CI/CD can be used with:
- [GitHub](
......@@ -110,9 +110,6 @@ The repository will push soon. To force a push, click the appropriate button.
> - [Introduced]( in GitLab Enterprise Edition 8.2.
> - [Added Git LFS support]( in [GitLab Starter]( 11.11.
NOTE: **Note:** This feature [is available for free]( to users until March 22nd, 2020.
You can set up a repository to automatically have its branches, tags, and commits updated from an
upstream repository.
......@@ -22,6 +22,33 @@ and private. See [Public access](../public_access/ for more inf
Project snippets are always related to a specific project.
See [Project features](project/ for more information.
## Create a snippet
To create a personal snippet, click the plus icon (**{plus-square-o}**)
on the top navigation and select **New snippet** from the dropdown menu:
![New personal snippet from non-project pages](img/new_personal_snippet_v12_10.png)
If you're on a project's page but you want to create a new personal snippet,
click the plus icon (**{plus-square-o}**) and select **New snippet** from the
lower part of the dropdown (**GitLab** on; **Your Instance** on
self-managed instances):
![New personal snippet from project pages](img/new_personal_snippet_from_project_v12_10.png)
To create a project snippet, navigate to your project's page and click the
plus icon (**{plus-square-o}**), then select **New snippet** from the upper
part of the dropdown (**This project**).
![New personal snippet from project pages](img/new_project_snippet_from_project_v12_10.png)
From there, add the **Title**, **Description**, and a **File** name with the
appropriate extension (for example, `example.rb`, `index.html`).
CAUTION: **Warning:**
Make sure to add the file name to get code highlighting and to avoid this
[copy-pasting bug](
## Discover snippets
There are two main ways of how you can discover snippets in GitLab.
# frozen_string_literal: true
FactoryBot.define do
factory :project_alerting_setting, class: 'Alerting::ProjectAlertingSetting' do
token { 'access_token_123' }
# frozen_string_literal: true
require 'spec_helper'
describe Alerting::ProjectAlertingSetting do
let_it_be(:project) { create(:project) }
subject { create(:project_alerting_setting, project: project) }
describe 'Associations' do
it { belong_to(:project) }
describe '#token' do
context 'when set' do
let(:token) { SecureRandom.hex }
subject do
create(:project_alerting_setting, project: project, token: token)
it 'reads the token' do
expect(subject.token).to eq(token)
expect(subject.encrypted_token).not_to be_nil
expect(subject.encrypted_token_iv).not_to be_nil
context 'when not set' do
before do
subject.token = nil
it 'generates a token before validation' do
expect(subject).to be_valid
expect(subject.token).to match(/\A\h{32}\z/)
......@@ -70,6 +70,7 @@
it { have_one(:auto_devops).class_name('ProjectAutoDevops') }
it { have_one(:error_tracking_setting).class_name('ErrorTracking::ProjectErrorTrackingSetting') }
it { have_one(:project_setting) }
it { have_one(:alerting_setting).class_name('Alerting::ProjectAlertingSetting') }
it { have_many(:commit_statuses) }
it { have_many(:ci_pipelines) }
it { have_many(:ci_refs) }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment