Commit 71da67f3 authored by GitLab Bot's avatar GitLab Bot

Add latest changes from gitlab-org/gitlab@master

parent f2dfd9ee
# 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
private
def ensure_token
self.token ||= generate_token
end
def generate_token
SecureRandom.hex
end
end
end
...@@ -199,6 +199,7 @@ class Project < ApplicationRecord ...@@ -199,6 +199,7 @@ class Project < ApplicationRecord
has_one :metrics_setting, inverse_of: :project, class_name: 'ProjectMetricsSetting' has_one :metrics_setting, inverse_of: :project, class_name: 'ProjectMetricsSetting'
has_one :grafana_integration, inverse_of: :project has_one :grafana_integration, inverse_of: :project
has_one :project_setting, ->(project) { where_or_create_by(project: project) }, 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 # Merge Requests for target project should be removed with it
has_many :merge_requests, foreign_key: 'target_project_id', inverse_of: :target_project has_many :merge_requests, foreign_key: 'target_project_id', inverse_of: :target_project
...@@ -332,6 +333,7 @@ class Project < ApplicationRecord ...@@ -332,6 +333,7 @@ class Project < ApplicationRecord
accepts_nested_attributes_for :metrics_setting, update_only: true, allow_destroy: true 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 :grafana_integration, update_only: true, allow_destroy: true
accepts_nested_attributes_for :prometheus_service, update_only: 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?, delegate :feature_available?, :builds_enabled?, :wiki_enabled?,
:merge_requests_enabled?, :forking_enabled?, :issues_enabled?, :merge_requests_enabled?, :forking_enabled?, :issues_enabled?,
......
...@@ -6,10 +6,6 @@ type: index, howto ...@@ -6,10 +6,6 @@ type: index, howto
>[Introduced][ee-4642] in [GitLab Premium][eep] 10.6. >[Introduced][ee-4642] in [GitLab Premium][eep] 10.6.
NOTE: **Note:**
This feature [is available for free](https://about.gitlab.com/blog/2019/09/09/ci-cd-github-extended-again/) to
GitLab.com users until March 22nd, 2020.
GitLab CI/CD can be used with: GitLab CI/CD can be used with:
- [GitHub](github_integration.md). - [GitHub](github_integration.md).
......
...@@ -110,9 +110,6 @@ The repository will push soon. To force a push, click the appropriate button. ...@@ -110,9 +110,6 @@ The repository will push soon. To force a push, click the appropriate button.
> - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/51) in GitLab Enterprise Edition 8.2. > - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/51) in GitLab Enterprise Edition 8.2.
> - [Added Git LFS support](https://gitlab.com/gitlab-org/gitlab/issues/10871) in [GitLab Starter](https://about.gitlab.com/pricing/) 11.11. > - [Added Git LFS support](https://gitlab.com/gitlab-org/gitlab/issues/10871) in [GitLab Starter](https://about.gitlab.com/pricing/) 11.11.
NOTE: **Note:** This feature [is available for free](https://gitlab.com/gitlab-org/gitlab/issues/10361) to
GitLab.com users until March 22nd, 2020.
You can set up a repository to automatically have its branches, tags, and commits updated from an You can set up a repository to automatically have its branches, tags, and commits updated from an
upstream repository. upstream repository.
......
...@@ -22,6 +22,33 @@ and private. See [Public access](../public_access/public_access.md) for more inf ...@@ -22,6 +22,33 @@ and private. See [Public access](../public_access/public_access.md) for more inf
Project snippets are always related to a specific project. Project snippets are always related to a specific project.
See [Project features](project/index.md#project-features) for more information. See [Project features](project/index.md#project-features) 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 GitLab.com; **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](https://gitlab.com/gitlab-org/gitlab/-/issues/22870).
## Discover snippets ## Discover snippets
There are two main ways of how you can discover snippets in GitLab. 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
project
token { 'access_token_123' }
end
end
# 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 { is_expected.to belong_to(:project) }
end
describe '#token' do
context 'when set' do
let(:token) { SecureRandom.hex }
subject do
create(:project_alerting_setting, project: project, token: token)
end
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
end
end
context 'when not set' do
before do
subject.token = nil
end
it 'generates a token before validation' do
expect(subject).to be_valid
expect(subject.token).to match(/\A\h{32}\z/)
end
end
end
end
...@@ -70,6 +70,7 @@ describe Project do ...@@ -70,6 +70,7 @@ describe Project do
it { is_expected.to have_one(:auto_devops).class_name('ProjectAutoDevops') } it { is_expected.to have_one(:auto_devops).class_name('ProjectAutoDevops') }
it { is_expected.to have_one(:error_tracking_setting).class_name('ErrorTracking::ProjectErrorTrackingSetting') } it { is_expected.to have_one(:error_tracking_setting).class_name('ErrorTracking::ProjectErrorTrackingSetting') }
it { is_expected.to have_one(:project_setting) } it { is_expected.to have_one(:project_setting) }
it { is_expected.to have_one(:alerting_setting).class_name('Alerting::ProjectAlertingSetting') }
it { is_expected.to have_many(:commit_statuses) } it { is_expected.to have_many(:commit_statuses) }
it { is_expected.to have_many(:ci_pipelines) } it { is_expected.to have_many(:ci_pipelines) }
it { is_expected.to have_many(:ci_refs) } it { is_expected.to 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