Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Dangerfile « changelog « danger - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6f045d7b5ab2281be41346baf3e2e6631d1daf8c (plain)
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
92
93
94
95
96
97
98
99
# frozen_string_literal: true
# rubocop:disable Style/SignalException

require 'yaml'

SEE_DOC = "See the [changelog documentation](https://docs.gitlab.com/ee/development/changelog.html)."

SUGGEST_MR_COMMENT = <<~SUGGEST_COMMENT
```suggestion
merge_request: %<mr_iid>s
```

#{SEE_DOC}
SUGGEST_COMMENT

def check_changelog_yaml(path)
  raw_file = File.read(path)
  yaml = YAML.safe_load(raw_file)

  fail "`title` should be set, in #{helper.html_link(path)}! #{SEE_DOC}" if yaml["title"].nil?
  fail "`type` should be set, in #{helper.html_link(path)}! #{SEE_DOC}" if yaml["type"].nil?

  return if helper.security_mr?
  return if helper.mr_iid.to_s.empty?

  cherry_pick_against_stable_branch = helper.cherry_pick_mr? && helper.stable_branch?

  if yaml["merge_request"].nil?
    mr_line = raw_file.lines.find_index("merge_request:\n")

    if mr_line
      markdown(format(SUGGEST_MR_COMMENT, mr_iid: helper.mr_iid), file: path, line: mr_line.succ)
    else
      message "Consider setting `merge_request` to #{helper.mr_iid} in #{helper.html_link(path)}. #{SEE_DOC}"
    end
  elsif yaml["merge_request"] != helper.mr_iid && !cherry_pick_against_stable_branch
    fail "Merge request ID was not set to #{helper.mr_iid}! #{SEE_DOC}"
  end
rescue Psych::Exception
  # YAML could not be parsed, fail the build.
  fail "#{helper.html_link(path)} isn't valid YAML! #{SEE_DOC}"
rescue StandardError => e
  warn "There was a problem trying to check the Changelog. Exception: #{e.class.name} - #{e.message}"
end

def check_changelog_path(path)
  ee_changes = project_helper.all_ee_changes.dup
  ee_changes.delete(path)

  if ee_changes.any? && !changelog.ee_changelog? && !changelog.required?
    warn "This MR has a Changelog file outside `ee/`, but code changes in `ee/`. Consider moving the Changelog file into `ee/`."
  end

  if ee_changes.empty? && changelog.ee_changelog?
    warn "This MR has a Changelog file in `ee/`, but no code changes in `ee/`. Consider moving the Changelog file outside `ee/`."
  end

  if ee_changes.any? && changelog.ee_changelog? && changelog.required_reasons.include?(:db_changes)
    warn "This MR has a Changelog file inside `ee/`, but there are database changes which [requires](https://docs.gitlab.com/ee/development/changelog.html#what-warrants-a-changelog-entry) the Changelog placement to be outside of `ee/`. Consider moving the Changelog file outside `ee/`."
  end
end

if git.modified_files.include?("CHANGELOG.md")
  fail changelog.modified_text
end

changelog_found = changelog.found

if changelog_found
  check_changelog_yaml(changelog_found)
  check_changelog_path(changelog_found)
elsif changelog.required?
  changelog.required_texts.each { |_, text| fail(text) } # rubocop:disable Lint/UnreachableLoop
elsif changelog.optional?
  message changelog.optional_text
end

message <<~MSG
  We are in the process of rolling out a new workflow for adding changelog entries. This new workflow uses Git commit subjects and Git trailers to generate changelogs. This new approach will soon replace the current YAML based approach.

  To ease the transition process, we recommend you start using both the old and new approach in parallel. This is not required at this time, but will make it easier to transition to the new approach in the future. To do so, pick the commit that should go in the changelog and add a `Changelog` trailer to it.  For example:

  ```
  This is my commit's subject line

  This is the optional commit body.

  Changelog: added
  ```

  The value of the `Changelog` trailer should be one of the following: added, fixed, changed, deprecated, removed, security, performance, other.

  For more information, take a look at the following resources:

  - https://gitlab.com/gitlab-com/gl-infra/delivery/-/issues/1564
  - https://docs.gitlab.com/ee/api/repositories.html#generate-changelog-data

  If you'd like to see the new approach in action, take a look at the commits in [the Omnibus repository](https://gitlab.com/gitlab-org/omnibus-gitlab/-/commits/master).
MSG