class Fastlane::Actions::GitlabChangelogAction

Public Class Methods

authors() click to toggle source
# File lib/fastlane/plugin/gitlab_changelog/actions/gitlab_changelog_action.rb, line 40
def self.authors
  ["Žilvinas Sebeika"]
end
available_options() click to toggle source
# File lib/fastlane/plugin/gitlab_changelog/actions/gitlab_changelog_action.rb, line 52
def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :current_branch,
                                  env_name: "CI_COMMIT_REF_NAME",
                                  description: "Current branch",
                                  optional: false),
    FastlaneCore::ConfigItem.new(key: :compare_branch_prefix,
                                  default_value: "release",
                                  description: "Compare branch prefix. Usually 'release' to compare against 'release/*.*.*' branches",
                                  optional: false),
    FastlaneCore::ConfigItem.new(key: :gitlab_API_baseURL,
                                  description: "GitLab API base URL (http://<gitLab_host>/api/v4)",
                                  optional: false),
    FastlaneCore::ConfigItem.new(key: :gitlab_project_id,
                                  env_name: "CI_PROJECT_ID",
                                  description: "GitLab Project ID (ENV['CI_PROJECT_ID'])",
                                  optional: false),
    FastlaneCore::ConfigItem.new(key: :gitlab_API_token,
                                  description: "GitLab API Token (ENV['GITLAB_API_TOKEN'])",
                                  optional: false)
  ]
end
description() click to toggle source
# File lib/fastlane/plugin/gitlab_changelog/actions/gitlab_changelog_action.rb, line 36
def self.description
  "Get changelog using GitLab API"
end
details() click to toggle source
# File lib/fastlane/plugin/gitlab_changelog/actions/gitlab_changelog_action.rb, line 48
def self.details
  "Fetch changelog between branches using GitLab API. Useful if you have GIT_DEPTH: 1 setting in CI config"
end
is_supported?(platform) click to toggle source
# File lib/fastlane/plugin/gitlab_changelog/actions/gitlab_changelog_action.rb, line 75
def self.is_supported?(platform)
  true
end
return_value() click to toggle source
# File lib/fastlane/plugin/gitlab_changelog/actions/gitlab_changelog_action.rb, line 44
def self.return_value
  "String containing commit messages (excluding branch merges). Separated by new_line"
end
run(params) click to toggle source
# File lib/fastlane/plugin/gitlab_changelog/actions/gitlab_changelog_action.rb, line 7
def self.run(params)
  require 'excon'

  to_branch = params[:current_branch].to_s
  from_branch = Helper::GitlabChangelogHelper.get_from_branch(params[:compare_branch_prefix].to_s, to_branch)
  endpoint = "#{params[:gitlab_API_baseURL]}/projects/#{params[:gitlab_project_id]}/repository/compare"

  UI.message("Fetching changeLog from: #{from_branch} to: #{to_branch} (GET #{endpoint})")

  compare_resp = Excon.get(
    endpoint,
    query: {
      from: from_branch,
      to: to_branch,
      private_token: params[:gitlab_API_token]
    }
  )

  change_log = JSON.parse(compare_resp.body)['commits']
                   .reject { |c| c['title'].start_with?("Merge branch") } # Filter out merges
                   .sort_by { |c| -Date.parse(c['created_at']).to_time.to_i }
                   .map { |c| "#{c['title']} (#{c['author_name']}) #{Date.parse(c['created_at'])}" }
                   .join("\n")

  puts("\n#{change_log}")

  change_log
end