Module: Gitlab::Danger::Changelog

Defined in:
lib/gitlab/danger/changelog.rb

Constant Summary collapse

NO_CHANGELOG_LABELS =
[
  'tooling',
  'tooling::pipelines',
  'tooling::workflow',
  'ci-build',
  'meta'
].freeze
NO_CHANGELOG_CATEGORIES =
%i[docs none].freeze
CREATE_CHANGELOG_COMMAND =
'bin/changelog -m %<mr_iid>s "%<mr_title>s"'
CREATE_EE_CHANGELOG_COMMAND =
'bin/changelog --ee -m %<mr_iid>s "%<mr_title>s"'
CHANGELOG_MODIFIED_URL_TEXT =
"**CHANGELOG.md was edited.** Please remove the additions and create a CHANGELOG entry.\n\n"
CHANGELOG_MISSING_URL_TEXT =
"**[CHANGELOG missing](https://docs.gitlab.com/ee/development/changelog.html)**:\n\n"
OPTIONAL_CHANGELOG_MESSAGE =
<<~MSG
If you want to create a changelog entry for GitLab FOSS, run the following:

    #{CREATE_CHANGELOG_COMMAND}

If you want to create a changelog entry for GitLab EE, run the following instead:

    #{CREATE_EE_CHANGELOG_COMMAND}

If this merge request [doesn't need a CHANGELOG entry](https://docs.gitlab.com/ee/development/changelog.html#what-warrants-a-changelog-entry), feel free to ignore this message.
MSG
REQUIRED_CHANGELOG_MESSAGE =
<<~MSG
To create a changelog entry, run the following:

    #{CREATE_CHANGELOG_COMMAND}

This merge request requires a changelog entry because it [introduces a database migration](https://docs.gitlab.com/ee/development/changelog.html#what-warrants-a-changelog-entry).
MSG

Instance Method Summary collapse

Instance Method Details

#ee_changelog?Boolean

Returns:

  • (Boolean)

51
52
53
# File 'lib/gitlab/danger/changelog.rb', line 51

def ee_changelog?
  found.start_with?('ee/')
end

#foundObject


47
48
49
# File 'lib/gitlab/danger/changelog.rb', line 47

def found
  @found ||= git.added_files.find { |path| path =~ %r{\A(ee/)?(changelogs/unreleased)(-ee)?/} }
end

#modified_textObject


55
56
57
58
# File 'lib/gitlab/danger/changelog.rb', line 55

def modified_text
  CHANGELOG_MODIFIED_URL_TEXT +
    format(OPTIONAL_CHANGELOG_MESSAGE, mr_iid: mr_iid, mr_title: sanitized_mr_title)
end

#optional?Boolean

Returns:

  • (Boolean)

43
44
45
# File 'lib/gitlab/danger/changelog.rb', line 43

def optional?
  categories_need_changelog? && without_no_changelog_label?
end

#optional_textObject


65
66
67
68
# File 'lib/gitlab/danger/changelog.rb', line 65

def optional_text
  CHANGELOG_MISSING_URL_TEXT +
    format(OPTIONAL_CHANGELOG_MESSAGE, mr_iid: mr_iid, mr_title: sanitized_mr_title)
end

#required?Boolean

Returns:

  • (Boolean)

39
40
41
# File 'lib/gitlab/danger/changelog.rb', line 39

def required?
  git.added_files.any? { |path| path =~ %r{\Adb/(migrate|post_migrate)/} }
end

#required_textObject


60
61
62
63
# File 'lib/gitlab/danger/changelog.rb', line 60

def required_text
  CHANGELOG_MISSING_URL_TEXT +
    format(REQUIRED_CHANGELOG_MESSAGE, mr_iid: mr_iid, mr_title: sanitized_mr_title)
end