1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
require 'yaml'
def lint_commit(commit)
trailer = commit.message.match(/^(?<name>Changelog):\s*(?<category>.+)$/i)
return :missing if trailer.nil? || trailer[:category].nil?
name = trailer[:name]
unless name == 'Changelog'
self.fail(
"The changelog trailer for commit #{commit.sha} must be `Changelog` (starting with a capital C), not `#{name}`"
)
return :invalid
end
category = trailer[:category]
return :valid if CATEGORIES.include?(category)
self.fail(
"Commit #{commit.sha} uses an invalid changelog category: #{category}"
)
:invalid
end
def presented_no_changelog_labels
NO_CHANGELOG_LABELS.map { |label| %(~"#{label}") }.join(', ')
end
NO_CHANGELOG_LABELS = [
'documentation',
'tooling',
'tooling::pipelines',
'tooling::workflow',
'ci-build',
'meta'
].freeze
CATEGORIES = YAML
.load_file(File.expand_path('../../.gitlab/changelog_config.yml', __dir__))
.fetch('categories')
.keys
.freeze
SEE_DOC = "See [the documentation](https://docs.gitlab.com/ee/development/changelog.html).".freeze
CHANGELOG_MISSING = <<~MSG.freeze
**[CHANGELOG missing](https://docs.gitlab.com/ee/development/changelog.html).**
To ceate a changelog, annotate one or more commits with the `Changelog` Git
trailer. If you want to annotate the latest commit, you can do so using `git
commit --amend`. If you want to annotate older or multiple commits, you need to
do so using `git rebase -i`.
When adding the trailer, you can use the following values:
- #{CATEGORIES.join("\n- ")}
For example:
```
This is the subject of your commit.
This would be the body of your commit containing some extra details.
Changelog: added
```
If your merge request doesn't warrant a CHANGELOG entry, consider adding any of
the #{presented_no_changelog_labels} labels.
#{SEE_DOC}
MSG
changelog_needed = (gitlab.mr_labels & NO_CHANGELOG_LABELS).empty?
if changelog_needed
checked = 0
git.commits.each do |commit|
case lint_commit(commit)
when :valid, :invalid
checked += 1
end
end
warn(CHANGELOG_MISSING) if checked.zero?
end
|