fastlane-plugin-github_api 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +824 -0
- data/lib/fastlane/plugin/github_api/actions/github_add_assignees_action.rb +191 -0
- data/lib/fastlane/plugin/github_api/actions/github_add_issue_comment_action.rb +184 -0
- data/lib/fastlane/plugin/github_api/actions/github_add_labels_action.rb +191 -0
- data/lib/fastlane/plugin/github_api/actions/github_api_action.rb +47 -0
- data/lib/fastlane/plugin/github_api/actions/github_check_pull_merged_action.rb +152 -0
- data/lib/fastlane/plugin/github_api/actions/github_create_commit_comment_reaction_action.rb +168 -0
- data/lib/fastlane/plugin/github_api/actions/github_create_issue_action.rb +199 -0
- data/lib/fastlane/plugin/github_api/actions/github_create_issue_comment_reaction_action.rb +168 -0
- data/lib/fastlane/plugin/github_api/actions/github_create_issue_reaction_action.rb +168 -0
- data/lib/fastlane/plugin/github_api/actions/github_create_label_action.rb +194 -0
- data/lib/fastlane/plugin/github_api/actions/github_create_milestone_action.rb +199 -0
- data/lib/fastlane/plugin/github_api/actions/github_create_pull_action.rb +202 -0
- data/lib/fastlane/plugin/github_api/actions/github_create_pull_comment_action.rb +229 -0
- data/lib/fastlane/plugin/github_api/actions/github_create_pull_comment_reaction_action.rb +168 -0
- data/lib/fastlane/plugin/github_api/actions/github_create_pull_review_action.rb +224 -0
- data/lib/fastlane/plugin/github_api/actions/github_create_repository_action.rb +230 -0
- data/lib/fastlane/plugin/github_api/actions/github_delete_commit_comment_reaction_action.rb +152 -0
- data/lib/fastlane/plugin/github_api/actions/github_delete_issue_comment_action.rb +153 -0
- data/lib/fastlane/plugin/github_api/actions/github_delete_issue_comment_reaction_action.rb +152 -0
- data/lib/fastlane/plugin/github_api/actions/github_delete_issue_reaction_action.rb +152 -0
- data/lib/fastlane/plugin/github_api/actions/github_delete_label_action.rb +164 -0
- data/lib/fastlane/plugin/github_api/actions/github_delete_milestone_action.rb +159 -0
- data/lib/fastlane/plugin/github_api/actions/github_delete_pull_comment_action.rb +144 -0
- data/lib/fastlane/plugin/github_api/actions/github_delete_pull_comment_reaction_action.rb +152 -0
- data/lib/fastlane/plugin/github_api/actions/github_delete_repository_action.rb +166 -0
- data/lib/fastlane/plugin/github_api/actions/github_dismiss_pull_review_action.rb +168 -0
- data/lib/fastlane/plugin/github_api/actions/github_get_issue_action.rb +166 -0
- data/lib/fastlane/plugin/github_api/actions/github_get_issue_comment_action.rb +174 -0
- data/lib/fastlane/plugin/github_api/actions/github_get_issue_event_action.rb +169 -0
- data/lib/fastlane/plugin/github_api/actions/github_get_issue_timeline_action.rb +199 -0
- data/lib/fastlane/plugin/github_api/actions/github_get_milestone_action.rb +167 -0
- data/lib/fastlane/plugin/github_api/actions/github_get_pull_action.rb +150 -0
- data/lib/fastlane/plugin/github_api/actions/github_get_pull_comment_action.rb +147 -0
- data/lib/fastlane/plugin/github_api/actions/github_get_pull_review_action.rb +137 -0
- data/lib/fastlane/plugin/github_api/actions/github_get_pull_review_comments_action.rb +181 -0
- data/lib/fastlane/plugin/github_api/actions/github_list_all_pull_comments_action.rb +186 -0
- data/lib/fastlane/plugin/github_api/actions/github_list_commit_comment_reactions_action.rb +183 -0
- data/lib/fastlane/plugin/github_api/actions/github_list_issue_comment_reactions_action.rb +183 -0
- data/lib/fastlane/plugin/github_api/actions/github_list_issue_comments_action.rb +197 -0
- data/lib/fastlane/plugin/github_api/actions/github_list_issue_events_action.rb +191 -0
- data/lib/fastlane/plugin/github_api/actions/github_list_issue_labels_action.rb +192 -0
- data/lib/fastlane/plugin/github_api/actions/github_list_issue_reactions_action.rb +183 -0
- data/lib/fastlane/plugin/github_api/actions/github_list_issues_action.rb +236 -0
- data/lib/fastlane/plugin/github_api/actions/github_list_milestones_action.rb +205 -0
- data/lib/fastlane/plugin/github_api/actions/github_list_pull_comment_reactions_action.rb +183 -0
- data/lib/fastlane/plugin/github_api/actions/github_list_pull_comments_action.rb +203 -0
- data/lib/fastlane/plugin/github_api/actions/github_list_pull_commits_action.rb +175 -0
- data/lib/fastlane/plugin/github_api/actions/github_list_pull_files_action.rb +174 -0
- data/lib/fastlane/plugin/github_api/actions/github_list_pull_reviewers_action.rb +163 -0
- data/lib/fastlane/plugin/github_api/actions/github_list_pull_reviews_action.rb +175 -0
- data/lib/fastlane/plugin/github_api/actions/github_list_pulls_action.rb +206 -0
- data/lib/fastlane/plugin/github_api/actions/github_list_repo_issue_events_action.rb +185 -0
- data/lib/fastlane/plugin/github_api/actions/github_list_repo_labels_action.rb +184 -0
- data/lib/fastlane/plugin/github_api/actions/github_lock_issue_action.rb +180 -0
- data/lib/fastlane/plugin/github_api/actions/github_merge_pull_action.rb +191 -0
- data/lib/fastlane/plugin/github_api/actions/github_remove_all_labels_action.rb +160 -0
- data/lib/fastlane/plugin/github_api/actions/github_remove_assignees_action.rb +195 -0
- data/lib/fastlane/plugin/github_api/actions/github_remove_label_action.rb +172 -0
- data/lib/fastlane/plugin/github_api/actions/github_remove_pull_reviewers_action.rb +169 -0
- data/lib/fastlane/plugin/github_api/actions/github_request_pull_review_action.rb +169 -0
- data/lib/fastlane/plugin/github_api/actions/github_set_labels_action.rb +191 -0
- data/lib/fastlane/plugin/github_api/actions/github_submit_pull_comment_action.rb +185 -0
- data/lib/fastlane/plugin/github_api/actions/github_submit_pull_review_action.rb +187 -0
- data/lib/fastlane/plugin/github_api/actions/github_unlock_issue_action.rb +157 -0
- data/lib/fastlane/plugin/github_api/actions/github_update_issue_action.rb +202 -0
- data/lib/fastlane/plugin/github_api/actions/github_update_issue_comment_action.rb +172 -0
- data/lib/fastlane/plugin/github_api/actions/github_update_label_action.rb +204 -0
- data/lib/fastlane/plugin/github_api/actions/github_update_milestone_action.rb +198 -0
- data/lib/fastlane/plugin/github_api/actions/github_update_pull_action.rb +191 -0
- data/lib/fastlane/plugin/github_api/actions/github_update_pull_branch_action.rb +158 -0
- data/lib/fastlane/plugin/github_api/actions/github_update_pull_comment_action.rb +156 -0
- data/lib/fastlane/plugin/github_api/actions/github_update_pull_review_action.rb +151 -0
- data/lib/fastlane/plugin/github_api/helper/github_api_helper.rb +123 -0
- data/lib/fastlane/plugin/github_api/version.rb +5 -0
- data/lib/fastlane/plugin/github_api.rb +16 -0
- metadata +120 -0
@@ -0,0 +1,169 @@
|
|
1
|
+
require 'fastlane/action'
|
2
|
+
require_relative '../helper/github_api_helper'
|
3
|
+
|
4
|
+
module Fastlane
|
5
|
+
module Actions
|
6
|
+
module SharedValues
|
7
|
+
GITHUB_REQUEST_PULL_REVIEW_STATUS_CODE = :GITHUB_REQUEST_PULL_REVIEW_STATUS_CODE
|
8
|
+
GITHUB_REQUEST_PULL_REVIEW_RESPONSE = :GITHUB_REQUEST_PULL_REVIEW_RESPONSE
|
9
|
+
GITHUB_REQUEST_PULL_REVIEW_JSON = :GITHUB_REQUEST_PULL_REVIEW_JSON
|
10
|
+
end
|
11
|
+
|
12
|
+
class GithubRequestPullReviewAction < Action
|
13
|
+
class << self
|
14
|
+
def run(params)
|
15
|
+
require 'json'
|
16
|
+
|
17
|
+
# Prepare API call parameters
|
18
|
+
server_url = params[:server_url]
|
19
|
+
api_token = params[:api_token]
|
20
|
+
repo_owner = params[:repo_owner]
|
21
|
+
repo_name = params[:repo_name]
|
22
|
+
pull_number = params[:pull_number]
|
23
|
+
reviewers = params[:reviewers]
|
24
|
+
team_reviewers = params[:team_reviewers]
|
25
|
+
|
26
|
+
# Build the body for the request
|
27
|
+
body = {}
|
28
|
+
body[:reviewers] = reviewers if reviewers && !reviewers.empty?
|
29
|
+
body[:team_reviewers] = team_reviewers if team_reviewers && !team_reviewers.empty?
|
30
|
+
|
31
|
+
# Build the path
|
32
|
+
path = "/repos/#{repo_owner}/#{repo_name}/pulls/#{pull_number}/requested_reviewers"
|
33
|
+
|
34
|
+
UI.message("Requesting reviewers for pull request ##{pull_number} from #{repo_owner}/#{repo_name}")
|
35
|
+
response = Helper::GithubApiHelper.github_api_request(
|
36
|
+
token: api_token,
|
37
|
+
path: path,
|
38
|
+
params: body,
|
39
|
+
method: :post,
|
40
|
+
server_url: server_url
|
41
|
+
)
|
42
|
+
|
43
|
+
status_code = response[:status]
|
44
|
+
json_response = response[:json]
|
45
|
+
result = {
|
46
|
+
status: status_code,
|
47
|
+
body: response[:body],
|
48
|
+
json: json_response
|
49
|
+
}
|
50
|
+
|
51
|
+
if status_code.between?(200, 299)
|
52
|
+
reviewer_count = reviewers ? reviewers.count : 0
|
53
|
+
team_count = team_reviewers ? team_reviewers.count : 0
|
54
|
+
UI.success("Successfully requested #{reviewer_count} reviewers and #{team_count} team reviewers for pull request ##{pull_number}")
|
55
|
+
else
|
56
|
+
UI.error("Error requesting reviewers: #{status_code}")
|
57
|
+
UI.error(response[:body])
|
58
|
+
UI.user_error!("GitHub API returned #{status_code}: #{response[:body]}")
|
59
|
+
return nil
|
60
|
+
end
|
61
|
+
|
62
|
+
# Store the results in shared values
|
63
|
+
Actions.lane_context[SharedValues::GITHUB_REQUEST_PULL_REVIEW_STATUS_CODE] = status_code
|
64
|
+
Actions.lane_context[SharedValues::GITHUB_REQUEST_PULL_REVIEW_RESPONSE] = response[:body]
|
65
|
+
Actions.lane_context[SharedValues::GITHUB_REQUEST_PULL_REVIEW_JSON] = json_response
|
66
|
+
|
67
|
+
return result
|
68
|
+
end
|
69
|
+
|
70
|
+
#####################################################
|
71
|
+
# @!group Documentation
|
72
|
+
#####################################################
|
73
|
+
|
74
|
+
def description
|
75
|
+
"Requests reviewers for a pull request"
|
76
|
+
end
|
77
|
+
|
78
|
+
def details
|
79
|
+
[
|
80
|
+
"Requests reviewers for a pull request.",
|
81
|
+
"You must provide your GitHub Personal token (get one from https://github.com/settings/tokens/new).",
|
82
|
+
"API Documentation: https://docs.github.com/en/rest/pulls/review-requests#request-reviewers-for-a-pull-request"
|
83
|
+
].join("\n")
|
84
|
+
end
|
85
|
+
|
86
|
+
def available_options
|
87
|
+
[
|
88
|
+
FastlaneCore::ConfigItem.new(key: :api_token,
|
89
|
+
env_name: "GITHUB_API_TOKEN",
|
90
|
+
description: "GitHub API token",
|
91
|
+
optional: false,
|
92
|
+
sensitive: true,
|
93
|
+
code_gen_sensitive: true,
|
94
|
+
default_value: ENV["GITHUB_API_TOKEN"],
|
95
|
+
verify_block: proc do |value|
|
96
|
+
UI.user_error!("No GitHub API token given, pass using `api_token: 'token'`") if value.to_s.empty?
|
97
|
+
end),
|
98
|
+
FastlaneCore::ConfigItem.new(key: :server_url,
|
99
|
+
env_name: "GITHUB_API_SERVER_URL",
|
100
|
+
description: "GitHub API server URL",
|
101
|
+
optional: true,
|
102
|
+
default_value: "https://api.github.com"),
|
103
|
+
FastlaneCore::ConfigItem.new(key: :repo_owner,
|
104
|
+
env_name: "GITHUB_API_REPO_OWNER",
|
105
|
+
description: "Owner of the repository",
|
106
|
+
optional: false),
|
107
|
+
FastlaneCore::ConfigItem.new(key: :repo_name,
|
108
|
+
env_name: "GITHUB_API_REPO_NAME",
|
109
|
+
description: "Name of the repository",
|
110
|
+
optional: false),
|
111
|
+
FastlaneCore::ConfigItem.new(key: :pull_number,
|
112
|
+
env_name: "GITHUB_API_PULL_NUMBER",
|
113
|
+
description: "The number of the pull request",
|
114
|
+
optional: false,
|
115
|
+
type: Integer),
|
116
|
+
FastlaneCore::ConfigItem.new(key: :reviewers,
|
117
|
+
env_name: "GITHUB_API_PULL_REVIEWERS",
|
118
|
+
description: "An array of user logins that will be requested to review",
|
119
|
+
optional: true,
|
120
|
+
type: Array),
|
121
|
+
FastlaneCore::ConfigItem.new(key: :team_reviewers,
|
122
|
+
env_name: "GITHUB_API_PULL_TEAM_REVIEWERS",
|
123
|
+
description: "An array of team slugs that will be requested to review",
|
124
|
+
optional: true,
|
125
|
+
type: Array)
|
126
|
+
]
|
127
|
+
end
|
128
|
+
|
129
|
+
def output
|
130
|
+
[
|
131
|
+
['GITHUB_REQUEST_PULL_REVIEW_STATUS_CODE', 'The status code returned by the GitHub API'],
|
132
|
+
['GITHUB_REQUEST_PULL_REVIEW_RESPONSE', 'The full response body returned by the GitHub API'],
|
133
|
+
['GITHUB_REQUEST_PULL_REVIEW_JSON', 'The parsed JSON response returned by the GitHub API']
|
134
|
+
]
|
135
|
+
end
|
136
|
+
|
137
|
+
def return_value
|
138
|
+
"Returns a hash containing the status code, response body, and parsed JSON response from the GitHub API."
|
139
|
+
end
|
140
|
+
|
141
|
+
def authors
|
142
|
+
["crazymanish"]
|
143
|
+
end
|
144
|
+
|
145
|
+
def is_supported?(platform)
|
146
|
+
true
|
147
|
+
end
|
148
|
+
|
149
|
+
def example_code
|
150
|
+
[
|
151
|
+
'github_request_pull_review(
|
152
|
+
repo_owner: "octocat",
|
153
|
+
repo_name: "Hello-World",
|
154
|
+
pull_number: 42,
|
155
|
+
reviewers: ["username1", "username2"]
|
156
|
+
)',
|
157
|
+
'github_request_pull_review(
|
158
|
+
repo_owner: "octocat",
|
159
|
+
repo_name: "Hello-World",
|
160
|
+
pull_number: 42,
|
161
|
+
reviewers: ["username1"],
|
162
|
+
team_reviewers: ["engineering-team"]
|
163
|
+
)'
|
164
|
+
]
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
@@ -0,0 +1,191 @@
|
|
1
|
+
require 'fastlane/action'
|
2
|
+
require_relative '../helper/github_api_helper'
|
3
|
+
|
4
|
+
module Fastlane
|
5
|
+
module Actions
|
6
|
+
module SharedValues
|
7
|
+
GITHUB_SET_LABELS_RESPONSE = :GITHUB_SET_LABELS_RESPONSE
|
8
|
+
GITHUB_SET_LABELS_JSON = :GITHUB_SET_LABELS_JSON
|
9
|
+
GITHUB_SET_LABELS_STATUS_CODE = :GITHUB_SET_LABELS_STATUS_CODE
|
10
|
+
end
|
11
|
+
|
12
|
+
class GithubSetLabelsAction < Action
|
13
|
+
class << self
|
14
|
+
def run(params)
|
15
|
+
token = params[:api_token]
|
16
|
+
repo_owner = params[:repo_owner]
|
17
|
+
repo_name = params[:repo_name]
|
18
|
+
issue_number = params[:issue_number]
|
19
|
+
labels = params[:labels]
|
20
|
+
server_url = params[:server_url]
|
21
|
+
|
22
|
+
# Validate parameters (additional validation beyond what's in ConfigItem)
|
23
|
+
UI.user_error!("No GitHub issue number given, pass using `issue_number: 123`") unless issue_number.to_s.length > 0
|
24
|
+
UI.user_error!("No labels provided, pass using `labels: ['bug', 'feature']`") if labels.nil? || labels.empty?
|
25
|
+
|
26
|
+
# Prepare request parameters
|
27
|
+
path = "/repos/#{repo_owner}/#{repo_name}/issues/#{issue_number}/labels"
|
28
|
+
|
29
|
+
# Build body parameters
|
30
|
+
body_params = {
|
31
|
+
labels: labels
|
32
|
+
}
|
33
|
+
|
34
|
+
# Make the request
|
35
|
+
UI.message("Setting labels on issue ##{issue_number} in #{repo_owner}/#{repo_name}")
|
36
|
+
response = Helper::GithubApiHelper.github_api_request(
|
37
|
+
token: token,
|
38
|
+
path: path,
|
39
|
+
params: body_params,
|
40
|
+
method: :put,
|
41
|
+
server_url: server_url
|
42
|
+
)
|
43
|
+
|
44
|
+
status_code = response.key?('status') ? response['status'] : nil
|
45
|
+
result = {
|
46
|
+
status: status_code,
|
47
|
+
body: response,
|
48
|
+
json: response
|
49
|
+
}
|
50
|
+
|
51
|
+
if response.key?('error')
|
52
|
+
UI.error("GitHub responded with an error: #{response['error']}")
|
53
|
+
UI.user_error!("GitHub API error: #{response['error']}")
|
54
|
+
return nil
|
55
|
+
end
|
56
|
+
|
57
|
+
if response['message'] && status_code && status_code >= 400
|
58
|
+
UI.error("GitHub API error: #{response['message']}")
|
59
|
+
UI.user_error!("GitHub API error: #{response['message']} (Status code: #{status_code})")
|
60
|
+
return nil
|
61
|
+
end
|
62
|
+
|
63
|
+
# Print labels for confirmation
|
64
|
+
if response.is_a?(Array) && !response.empty?
|
65
|
+
label_names = response.map { |label| label['name'] }.join(', ')
|
66
|
+
UI.success("Successfully set labels on issue ##{issue_number}: #{label_names}")
|
67
|
+
else
|
68
|
+
UI.success("Successfully updated labels on issue ##{issue_number}")
|
69
|
+
end
|
70
|
+
|
71
|
+
# Set the shared values
|
72
|
+
Actions.lane_context[SharedValues::GITHUB_SET_LABELS_STATUS_CODE] = status_code
|
73
|
+
Actions.lane_context[SharedValues::GITHUB_SET_LABELS_RESPONSE] = response
|
74
|
+
Actions.lane_context[SharedValues::GITHUB_SET_LABELS_JSON] = response
|
75
|
+
|
76
|
+
return result
|
77
|
+
end
|
78
|
+
|
79
|
+
#####################################################
|
80
|
+
# @!group Documentation
|
81
|
+
#####################################################
|
82
|
+
|
83
|
+
def description
|
84
|
+
"Replaces all labels on a GitHub issue"
|
85
|
+
end
|
86
|
+
|
87
|
+
def details
|
88
|
+
[
|
89
|
+
"This action replaces all existing labels on an issue with the specified list of labels.",
|
90
|
+
"It requires a valid GitHub API token with appropriate permissions.",
|
91
|
+
"Documentation: [https://docs.github.com/en/rest/issues/labels](https://docs.github.com/en/rest/issues/labels)"
|
92
|
+
].join("\n")
|
93
|
+
end
|
94
|
+
|
95
|
+
def available_options
|
96
|
+
[
|
97
|
+
FastlaneCore::ConfigItem.new(key: :api_token,
|
98
|
+
env_name: "GITHUB_API_TOKEN",
|
99
|
+
description: "GitHub API token with repo permissions",
|
100
|
+
optional: false,
|
101
|
+
type: String,
|
102
|
+
sensitive: true,
|
103
|
+
code_gen_sensitive: true,
|
104
|
+
default_value: ENV["GITHUB_API_TOKEN"],
|
105
|
+
verify_block: proc do |value|
|
106
|
+
UI.user_error!("No GitHub API token given, pass using `api_token: 'token'`") if value.to_s.empty?
|
107
|
+
end),
|
108
|
+
FastlaneCore::ConfigItem.new(key: :server_url,
|
109
|
+
env_name: "GITHUB_API_SERVER_URL",
|
110
|
+
description: "GitHub API server URL",
|
111
|
+
optional: true,
|
112
|
+
default_value: "https://api.github.com"),
|
113
|
+
FastlaneCore::ConfigItem.new(key: :repo_owner,
|
114
|
+
env_name: "GITHUB_API_REPO_OWNER",
|
115
|
+
description: "Repository owner (organization or username)",
|
116
|
+
optional: false,
|
117
|
+
type: String,
|
118
|
+
verify_block: proc do |value|
|
119
|
+
UI.user_error!("No repository owner provided, pass using `repo_owner: 'owner'`") if value.to_s.empty?
|
120
|
+
end),
|
121
|
+
FastlaneCore::ConfigItem.new(key: :repo_name,
|
122
|
+
env_name: "GITHUB_API_REPO_NAME",
|
123
|
+
description: "Repository name",
|
124
|
+
optional: false,
|
125
|
+
type: String,
|
126
|
+
verify_block: proc do |value|
|
127
|
+
UI.user_error!("No repository name provided, pass using `repo_name: 'name'`") if value.to_s.empty?
|
128
|
+
end),
|
129
|
+
FastlaneCore::ConfigItem.new(key: :issue_number,
|
130
|
+
env_name: "GITHUB_API_ISSUE_NUMBER",
|
131
|
+
description: "The issue number to set labels on",
|
132
|
+
optional: false,
|
133
|
+
type: Integer),
|
134
|
+
FastlaneCore::ConfigItem.new(key: :labels,
|
135
|
+
description: "Array of label names to set on the issue",
|
136
|
+
optional: false,
|
137
|
+
type: Array,
|
138
|
+
verify_block: proc do |value|
|
139
|
+
UI.user_error!("No labels provided, pass using `labels: ['bug']`") if value.nil? || value.empty?
|
140
|
+
end)
|
141
|
+
]
|
142
|
+
end
|
143
|
+
|
144
|
+
def output
|
145
|
+
[
|
146
|
+
['GITHUB_SET_LABELS_STATUS_CODE', 'The status code returned from the GitHub API'],
|
147
|
+
['GITHUB_SET_LABELS_RESPONSE', 'The full response from the GitHub API'],
|
148
|
+
['GITHUB_SET_LABELS_JSON', 'The JSON data returned from the GitHub API']
|
149
|
+
]
|
150
|
+
end
|
151
|
+
|
152
|
+
def return_value
|
153
|
+
"A hash including the HTTP status code (:status), the response body (:body), and the parsed JSON (:json)."
|
154
|
+
end
|
155
|
+
|
156
|
+
def authors
|
157
|
+
["crazymanish"]
|
158
|
+
end
|
159
|
+
|
160
|
+
def example_code
|
161
|
+
[
|
162
|
+
'github_set_labels(
|
163
|
+
api_token: ENV["GITHUB_API_TOKEN"],
|
164
|
+
repo_owner: "fastlane",
|
165
|
+
repo_name: "fastlane",
|
166
|
+
issue_number: 123,
|
167
|
+
labels: ["feature", "reviewed"]
|
168
|
+
)',
|
169
|
+
'# You can also access the response data
|
170
|
+
result = github_set_labels(
|
171
|
+
api_token: ENV["GITHUB_API_TOKEN"],
|
172
|
+
repo_owner: "fastlane",
|
173
|
+
repo_name: "fastlane",
|
174
|
+
issue_number: 123,
|
175
|
+
labels: ["bug", "critical"]
|
176
|
+
)
|
177
|
+
UI.message("Labels set: #{result[:json].map { |label| label["name"] }.join(", ")}")'
|
178
|
+
]
|
179
|
+
end
|
180
|
+
|
181
|
+
def category
|
182
|
+
:source_control
|
183
|
+
end
|
184
|
+
|
185
|
+
def is_supported?(platform)
|
186
|
+
true
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
@@ -0,0 +1,185 @@
|
|
1
|
+
require 'fastlane/action'
|
2
|
+
require_relative '../helper/github_api_helper'
|
3
|
+
|
4
|
+
module Fastlane
|
5
|
+
module Actions
|
6
|
+
module SharedValues
|
7
|
+
GITHUB_SUBMIT_PULL_COMMENT_STATUS_CODE = :GITHUB_SUBMIT_PULL_COMMENT_STATUS_CODE
|
8
|
+
GITHUB_SUBMIT_PULL_COMMENT_RESPONSE = :GITHUB_SUBMIT_PULL_COMMENT_RESPONSE
|
9
|
+
GITHUB_SUBMIT_PULL_COMMENT_JSON = :GITHUB_SUBMIT_PULL_COMMENT_JSON
|
10
|
+
end
|
11
|
+
|
12
|
+
class GithubSubmitPullCommentAction < Action
|
13
|
+
class << self
|
14
|
+
def run(params)
|
15
|
+
require 'json'
|
16
|
+
|
17
|
+
# Prepare API call parameters
|
18
|
+
server_url = params[:server_url]
|
19
|
+
api_token = params[:api_token]
|
20
|
+
repo_owner = params[:repo_owner]
|
21
|
+
repo_name = params[:repo_name]
|
22
|
+
pull_number = params[:pull_number]
|
23
|
+
body = params[:body]
|
24
|
+
commit_id = params[:commit_id]
|
25
|
+
path = params[:path]
|
26
|
+
position = params[:position]
|
27
|
+
|
28
|
+
# Build the body for the request
|
29
|
+
request_body = {
|
30
|
+
body: body
|
31
|
+
}
|
32
|
+
|
33
|
+
request_body[:commit_id] = commit_id if commit_id
|
34
|
+
request_body[:path] = path if path
|
35
|
+
request_body[:position] = position if position
|
36
|
+
|
37
|
+
# Build the path
|
38
|
+
api_path = "/repos/#{repo_owner}/#{repo_name}/pulls/#{pull_number}/comments"
|
39
|
+
|
40
|
+
UI.message("Creating a comment on pull request ##{pull_number} in #{repo_owner}/#{repo_name}")
|
41
|
+
response = Helper::GithubApiHelper.github_api_request(
|
42
|
+
token: api_token,
|
43
|
+
path: api_path,
|
44
|
+
params: request_body,
|
45
|
+
method: :post,
|
46
|
+
server_url: server_url
|
47
|
+
)
|
48
|
+
|
49
|
+
status_code = response[:status]
|
50
|
+
json_response = response[:json]
|
51
|
+
result = {
|
52
|
+
status: status_code,
|
53
|
+
body: response[:body],
|
54
|
+
json: json_response
|
55
|
+
}
|
56
|
+
|
57
|
+
if status_code.between?(200, 299)
|
58
|
+
UI.success("Successfully created a comment on pull request ##{pull_number}")
|
59
|
+
else
|
60
|
+
UI.error("Error creating comment: #{status_code}")
|
61
|
+
UI.error(response[:body])
|
62
|
+
UI.user_error!("GitHub API returned #{status_code}: #{response[:body]}")
|
63
|
+
return nil
|
64
|
+
end
|
65
|
+
|
66
|
+
# Store the results in shared values
|
67
|
+
Actions.lane_context[SharedValues::GITHUB_SUBMIT_PULL_COMMENT_STATUS_CODE] = status_code
|
68
|
+
Actions.lane_context[SharedValues::GITHUB_SUBMIT_PULL_COMMENT_RESPONSE] = response[:body]
|
69
|
+
Actions.lane_context[SharedValues::GITHUB_SUBMIT_PULL_COMMENT_JSON] = json_response
|
70
|
+
|
71
|
+
return result
|
72
|
+
end
|
73
|
+
|
74
|
+
#####################################################
|
75
|
+
# @!group Documentation
|
76
|
+
#####################################################
|
77
|
+
|
78
|
+
def description
|
79
|
+
"Create a review comment on a pull request"
|
80
|
+
end
|
81
|
+
|
82
|
+
def details
|
83
|
+
[
|
84
|
+
"Creates a review comment on a pull request.",
|
85
|
+
"You must provide your GitHub Personal token (get one from https://github.com/settings/tokens/new).",
|
86
|
+
"API Documentation: https://docs.github.com/en/rest/pulls/comments#create-a-review-comment-for-a-pull-request"
|
87
|
+
].join("\n")
|
88
|
+
end
|
89
|
+
|
90
|
+
def available_options
|
91
|
+
[
|
92
|
+
FastlaneCore::ConfigItem.new(key: :api_token,
|
93
|
+
env_name: "GITHUB_API_TOKEN",
|
94
|
+
description: "GitHub API token",
|
95
|
+
optional: false,
|
96
|
+
sensitive: true,
|
97
|
+
code_gen_sensitive: true,
|
98
|
+
default_value: ENV["GITHUB_API_TOKEN"],
|
99
|
+
verify_block: proc do |value|
|
100
|
+
UI.user_error!("No GitHub API token given, pass using `api_token: 'token'`") if value.to_s.empty?
|
101
|
+
end),
|
102
|
+
FastlaneCore::ConfigItem.new(key: :server_url,
|
103
|
+
env_name: "GITHUB_API_SERVER_URL",
|
104
|
+
description: "GitHub server url",
|
105
|
+
optional: true,
|
106
|
+
default_value: "https://api.github.com"),
|
107
|
+
FastlaneCore::ConfigItem.new(key: :repo_owner,
|
108
|
+
env_name: "GITHUB_API_REPO_OWNER",
|
109
|
+
description: "Owner of the repository",
|
110
|
+
optional: false),
|
111
|
+
FastlaneCore::ConfigItem.new(key: :repo_name,
|
112
|
+
env_name: "GITHUB_API_REPO_NAME",
|
113
|
+
description: "Name of the repository",
|
114
|
+
optional: false),
|
115
|
+
FastlaneCore::ConfigItem.new(key: :pull_number,
|
116
|
+
env_name: "GITHUB_API_PULL_NUMBER",
|
117
|
+
description: "The number of the pull request",
|
118
|
+
optional: false,
|
119
|
+
type: Integer),
|
120
|
+
FastlaneCore::ConfigItem.new(key: :body,
|
121
|
+
env_name: "GITHUB_API_COMMENT_BODY",
|
122
|
+
description: "The body text of the comment",
|
123
|
+
optional: false,
|
124
|
+
type: String),
|
125
|
+
FastlaneCore::ConfigItem.new(key: :commit_id,
|
126
|
+
env_name: "GITHUB_API_COMMIT_ID",
|
127
|
+
description: "The SHA of the commit to comment on",
|
128
|
+
optional: true,
|
129
|
+
type: String),
|
130
|
+
FastlaneCore::ConfigItem.new(key: :path,
|
131
|
+
env_name: "GITHUB_API_FILE_PATH",
|
132
|
+
description: "The relative path to the file to comment on",
|
133
|
+
optional: true,
|
134
|
+
type: String),
|
135
|
+
FastlaneCore::ConfigItem.new(key: :position,
|
136
|
+
env_name: "GITHUB_API_FILE_POSITION",
|
137
|
+
description: "The position in the diff to comment on",
|
138
|
+
optional: true,
|
139
|
+
type: Integer)
|
140
|
+
]
|
141
|
+
end
|
142
|
+
|
143
|
+
def output
|
144
|
+
[
|
145
|
+
['GITHUB_SUBMIT_PULL_COMMENT_STATUS_CODE', 'The status code returned by the GitHub API'],
|
146
|
+
['GITHUB_SUBMIT_PULL_COMMENT_RESPONSE', 'The full response body returned by the GitHub API'],
|
147
|
+
['GITHUB_SUBMIT_PULL_COMMENT_JSON', 'The parsed JSON response returned by the GitHub API']
|
148
|
+
]
|
149
|
+
end
|
150
|
+
|
151
|
+
def return_value
|
152
|
+
"Returns a hash containing the status code, response body, and parsed JSON response from the GitHub API."
|
153
|
+
end
|
154
|
+
|
155
|
+
def authors
|
156
|
+
["crazymanish"]
|
157
|
+
end
|
158
|
+
|
159
|
+
def is_supported?(platform)
|
160
|
+
true
|
161
|
+
end
|
162
|
+
|
163
|
+
def example_code
|
164
|
+
[
|
165
|
+
'github_submit_pull_comment(
|
166
|
+
repo_owner: "octocat",
|
167
|
+
repo_name: "Hello-World",
|
168
|
+
pull_number: 42,
|
169
|
+
body: "This is a great improvement!"
|
170
|
+
)',
|
171
|
+
'github_submit_pull_comment(
|
172
|
+
repo_owner: "octocat",
|
173
|
+
repo_name: "Hello-World",
|
174
|
+
pull_number: 42,
|
175
|
+
body: "This could be improved",
|
176
|
+
commit_id: "6dcb09b5b57875f334f61aebed695e2e4193db5e",
|
177
|
+
path: "file.rb",
|
178
|
+
position: 10
|
179
|
+
)'
|
180
|
+
]
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|