Class: Fastlane::Actions::MakeChangelogFromJenkinsAction

Inherits:
Fastlane::Action show all
Defined in:
fastlane/lib/fastlane/actions/make_changelog_from_jenkins.rb

Constant Summary

Constants inherited from Fastlane::Action

Fastlane::Action::AVAILABLE_CATEGORIES, Fastlane::Action::RETURN_TYPES

Class Method Summary collapse

Methods inherited from Fastlane::Action

action_name, author, deprecated_notes, lane_context, method_missing, other_action, return_type, return_value, sample_return_value, shell_out_should_use_bundle_exec?, step_text

Class Method Details

.authorsObject


59
60
61
# File 'fastlane/lib/fastlane/actions/make_changelog_from_jenkins.rb', line 59

def self.authors
  ["mandrizzle"]
end

.available_optionsObject


39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'fastlane/lib/fastlane/actions/make_changelog_from_jenkins.rb', line 39

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :fallback_changelog,
                                 description: "Fallback changelog if there is not one on Jenkins, or it couldn't be read",
                                 optional: true,
                                 default_value: ""),
    FastlaneCore::ConfigItem.new(key: :include_commit_body,
                                 description: "Include the commit body along with the summary",
                                 optional: true,
                                 is_string: false,
                                 default_value: true)
  ]
end

.categoryObject


76
77
78
# File 'fastlane/lib/fastlane/actions/make_changelog_from_jenkins.rb', line 76

def self.category
  :misc
end

.descriptionObject


31
32
33
# File 'fastlane/lib/fastlane/actions/make_changelog_from_jenkins.rb', line 31

def self.description
  "Generate a changelog using the Changes section from the current Jenkins build"
end

.detailsObject


35
36
37
# File 'fastlane/lib/fastlane/actions/make_changelog_from_jenkins.rb', line 35

def self.details
  "This is useful when deploying automated builds. The changelog from Jenkins lists all the commit messages since the last build."
end

.example_codeObject


67
68
69
70
71
72
73
74
# File 'fastlane/lib/fastlane/actions/make_changelog_from_jenkins.rb', line 67

def self.example_code
  [
    'make_changelog_from_jenkins(
      # Optional, lets you set a changelog in the case is not generated on Jenkins or if ran outside of Jenkins
      fallback_changelog: "Bug fixes and performance enhancements"
    )'
  ]
end

.is_supported?(platform) ⇒ Boolean

Returns:


63
64
65
# File 'fastlane/lib/fastlane/actions/make_changelog_from_jenkins.rb', line 63

def self.is_supported?(platform)
  true
end

.outputObject


53
54
55
56
57
# File 'fastlane/lib/fastlane/actions/make_changelog_from_jenkins.rb', line 53

def self.output
  [
    ['FL_CHANGELOG', 'The changelog generated by Jenkins']
  ]
end

.run(params) ⇒ Object


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'fastlane/lib/fastlane/actions/make_changelog_from_jenkins.rb', line 8

def self.run(params)
  require 'json'
  require 'net/http'

  changelog = ""

  if Helper.ci? || Helper.test?
    # The "BUILD_URL" environment variable is set automatically by Jenkins in every build
    jenkins_api_url = URI(ENV["BUILD_URL"] + "api/json\?wrapper\=changes\&xpath\=//changeSet//comment")
    begin
      json = JSON.parse(Net::HTTP.get(jenkins_api_url))
      json['changeSet']['items'].each do |item|
        comment = params[:include_commit_body] ? item['comment'] : item['msg']
        changelog << comment.strip + "\n"
      end
    rescue => ex
      UI.error("Unable to read/parse changelog from jenkins: #{ex.message}")
    end
  end

  Actions.lane_context[SharedValues::FL_CHANGELOG] = changelog.strip.length > 0 ? changelog : params[:fallback_changelog]
end