Class: Fastlane::Actions::GitlabBranchDiffAction

Inherits:
Action
  • Object
show all
Defined in:
lib/fastlane/plugin/gitlab_branch_diff/actions/gitlab_branch_diff_action.rb

Class Method Summary collapse

Class Method Details

.authorsObject



51
52
53
# File 'lib/fastlane/plugin/gitlab_branch_diff/actions/gitlab_branch_diff_action.rb', line 51

def self.authors
  ["xiongzenghui"]
end

.available_optionsObject



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
100
101
# File 'lib/fastlane/plugin/gitlab_branch_diff/actions/gitlab_branch_diff_action.rb', line 63

def self.available_options
  [
    FastlaneCore::ConfigItem.new(
      key: :projectid,
      description: "gitlab project's id",
      verify_block: proc do |value|
        UI.user_error!("No projectid given, pass using `projectid: 'projectid'`") unless (value and not value.empty?)
      end
    ),
    FastlaneCore::ConfigItem.new(
      key: :host,
      description: "gitlab host",
      verify_block: proc do |value|
        UI.user_error!("No gitlab host given, pass using `host: 'host'`") unless (value and not value.empty?)
      end
    ),
    FastlaneCore::ConfigItem.new(
      key: :token,
      description: "gitlab token",
      verify_block: proc do |value|
        UI.user_error!("No gitlab token given, pass using `token: 'token'`") unless (value and not value.empty?)
      end
    ),
    FastlaneCore::ConfigItem.new(
      key: :src,
      description: 'source branch',
      verify_block: proc do |value|
        UI.user_error!("No source branch given, pass using `src: 'src'`") unless (value and not value.empty?)
      end
    ),
    FastlaneCore::ConfigItem.new(
      key: :dest,
      description: 'destination branch',
      verify_block: proc do |value|
        UI.user_error!("No destination branch given, pass using `dest: 'dest'`") unless (value and not value.empty?)
      end
    )
  ]
end

.descriptionObject



47
48
49
# File 'lib/fastlane/plugin/gitlab_branch_diff/actions/gitlab_branch_diff_action.rb', line 47

def self.description
  "gitlab compare two branch to get diffs"
end

.detailsObject



59
60
61
# File 'lib/fastlane/plugin/gitlab_branch_diff/actions/gitlab_branch_diff_action.rb', line 59

def self.details
  "gitlab compare two branch to get diffs"
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


103
104
105
106
107
108
109
# File 'lib/fastlane/plugin/gitlab_branch_diff/actions/gitlab_branch_diff_action.rb', line 103

def self.is_supported?(platform)
  # Adjust this if your plugin only works for a particular platform (iOS vs. Android, for example)
  # See: https://docs.fastlane.tools/advanced/#control-configuration-by-lane-and-by-platform
  #
  # [:ios, :mac, :android].include?(platform)
  true
end

.return_valueObject



55
56
57
# File 'lib/fastlane/plugin/gitlab_branch_diff/actions/gitlab_branch_diff_action.rb', line 55

def self.return_value
  "return true if success, otherwiase return false"
end

.run(params) ⇒ Object



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
# File 'lib/fastlane/plugin/gitlab_branch_diff/actions/gitlab_branch_diff_action.rb', line 12

def self.run(params)
  require 'gitlab'
  projectid = params[:projectid]
  host = params[:host]
  token = params[:token]
  src = params[:src]
  dest = params[:dest]

  gc = Gitlab.client(endpoint: host, private_token: token)
  # branchs = gc.branches(projectid.to_i, {page: 1, per_page: 1024})
  # pp "⚠️ branchs:"
  # pp branchs.map { |b|
  #   b.name
  # }

  diff = gc.compare(projectid, src, dest)
  pp ' 🎉' * 30
  pp diff

  if diff.compare_timeout == true 
    Fastlane::Actions.lane_context[Fastlane::Actions::SharedValues::GITLAB_BRANCH_DIFF_ERROR] = '❌ gitlab api timeout'
    return false
  end

  if diff.diffs.empty?
    Fastlane::Actions.lane_context[Fastlane::Actions::SharedValues::GITLAB_BRANCH_DIFF_ERROR] = '❌ no diff'
    return false
  end

  Fastlane::Actions.lane_context[Fastlane::Actions::SharedValues::GITLAB_BRANCH_DIFF_RESULT] = diff.diffs.map { |adif|
    adif.to_hash
  }
  true
end