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,191 @@
|
|
1
|
+
require 'fastlane/action'
|
2
|
+
require_relative '../helper/github_api_helper'
|
3
|
+
|
4
|
+
module Fastlane
|
5
|
+
module Actions
|
6
|
+
module SharedValues
|
7
|
+
GITHUB_UPDATE_PULL_STATUS_CODE = :GITHUB_UPDATE_PULL_STATUS_CODE
|
8
|
+
GITHUB_UPDATE_PULL_RESPONSE = :GITHUB_UPDATE_PULL_RESPONSE
|
9
|
+
GITHUB_UPDATE_PULL_JSON = :GITHUB_UPDATE_PULL_JSON
|
10
|
+
end
|
11
|
+
|
12
|
+
class GithubUpdatePullAction < 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
|
+
|
24
|
+
# Build the body for the update request
|
25
|
+
body = {}
|
26
|
+
body[:title] = params[:title] if params[:title]
|
27
|
+
body[:body] = params[:body] if params[:body]
|
28
|
+
body[:state] = params[:state] if params[:state]
|
29
|
+
body[:base] = params[:base] if params[:base]
|
30
|
+
body[:maintainer_can_modify] = params[:maintainer_can_modify] unless params[:maintainer_can_modify].nil?
|
31
|
+
|
32
|
+
# Build the path
|
33
|
+
path = "/repos/#{repo_owner}/#{repo_name}/pulls/#{pull_number}"
|
34
|
+
|
35
|
+
UI.message("Updating pull request ##{pull_number} from #{repo_owner}/#{repo_name}")
|
36
|
+
response = Helper::GithubApiHelper.github_api_request(
|
37
|
+
token: api_token,
|
38
|
+
path: path,
|
39
|
+
params: body,
|
40
|
+
method: :patch,
|
41
|
+
server_url: server_url
|
42
|
+
)
|
43
|
+
|
44
|
+
status_code = response[:status]
|
45
|
+
json_response = response[:json]
|
46
|
+
result = {
|
47
|
+
status: status_code,
|
48
|
+
body: response[:body],
|
49
|
+
json: json_response
|
50
|
+
}
|
51
|
+
|
52
|
+
if status_code.between?(200, 299)
|
53
|
+
UI.success("Successfully updated pull request ##{pull_number} from #{repo_owner}/#{repo_name}")
|
54
|
+
else
|
55
|
+
UI.error("Error updating pull request: #{status_code}")
|
56
|
+
UI.error(response[:body])
|
57
|
+
UI.user_error!("GitHub API returned #{status_code}: #{response[:body]}")
|
58
|
+
return nil
|
59
|
+
end
|
60
|
+
|
61
|
+
# Store the results in shared values
|
62
|
+
Actions.lane_context[SharedValues::GITHUB_UPDATE_PULL_STATUS_CODE] = status_code
|
63
|
+
Actions.lane_context[SharedValues::GITHUB_UPDATE_PULL_RESPONSE] = response[:body]
|
64
|
+
Actions.lane_context[SharedValues::GITHUB_UPDATE_PULL_JSON] = json_response
|
65
|
+
|
66
|
+
return result
|
67
|
+
end
|
68
|
+
|
69
|
+
#####################################################
|
70
|
+
# @!group Documentation
|
71
|
+
#####################################################
|
72
|
+
|
73
|
+
def description
|
74
|
+
"Updates a pull request in a GitHub repository"
|
75
|
+
end
|
76
|
+
|
77
|
+
def details
|
78
|
+
[
|
79
|
+
"Updates a specific pull request by its number.",
|
80
|
+
"You must provide your GitHub Personal token (get one from https://github.com/settings/tokens/new).",
|
81
|
+
"API Documentation: https://docs.github.com/en/rest/pulls/pulls#update-a-pull-request"
|
82
|
+
].join("\n")
|
83
|
+
end
|
84
|
+
|
85
|
+
def available_options
|
86
|
+
[
|
87
|
+
FastlaneCore::ConfigItem.new(key: :api_token,
|
88
|
+
env_name: "GITHUB_API_TOKEN",
|
89
|
+
description: "GitHub API token",
|
90
|
+
optional: false,
|
91
|
+
sensitive: true,
|
92
|
+
code_gen_sensitive: true,
|
93
|
+
default_value: ENV["GITHUB_API_TOKEN"],
|
94
|
+
verify_block: proc do |value|
|
95
|
+
UI.user_error!("No GitHub API token given, pass using `api_token: 'token'`") if value.to_s.empty?
|
96
|
+
end),
|
97
|
+
FastlaneCore::ConfigItem.new(key: :server_url,
|
98
|
+
env_name: "GITHUB_API_SERVER_URL",
|
99
|
+
description: "GitHub API server URL",
|
100
|
+
optional: true,
|
101
|
+
default_value: "https://api.github.com"),
|
102
|
+
FastlaneCore::ConfigItem.new(key: :repo_owner,
|
103
|
+
env_name: "GITHUB_API_REPO_OWNER",
|
104
|
+
description: "Owner of the repository",
|
105
|
+
optional: false),
|
106
|
+
FastlaneCore::ConfigItem.new(key: :repo_name,
|
107
|
+
env_name: "GITHUB_API_REPO_NAME",
|
108
|
+
description: "Name of the repository",
|
109
|
+
optional: false),
|
110
|
+
FastlaneCore::ConfigItem.new(key: :pull_number,
|
111
|
+
env_name: "GITHUB_API_PULL_NUMBER",
|
112
|
+
description: "The number of the pull request",
|
113
|
+
optional: false,
|
114
|
+
type: Integer),
|
115
|
+
FastlaneCore::ConfigItem.new(key: :title,
|
116
|
+
env_name: "GITHUB_API_PULL_TITLE",
|
117
|
+
description: "The title of the pull request",
|
118
|
+
optional: true,
|
119
|
+
type: String),
|
120
|
+
FastlaneCore::ConfigItem.new(key: :body,
|
121
|
+
env_name: "GITHUB_API_PULL_BODY",
|
122
|
+
description: "The contents of the pull request",
|
123
|
+
optional: true,
|
124
|
+
type: String),
|
125
|
+
FastlaneCore::ConfigItem.new(key: :state,
|
126
|
+
env_name: "GITHUB_API_PULL_STATE",
|
127
|
+
description: "State of the pull request (open, closed)",
|
128
|
+
optional: true,
|
129
|
+
type: String,
|
130
|
+
verify_block: proc do |value|
|
131
|
+
UI.user_error!("State must be either 'open' or 'closed'") unless ['open', 'closed'].include?(value)
|
132
|
+
end),
|
133
|
+
FastlaneCore::ConfigItem.new(key: :base,
|
134
|
+
env_name: "GITHUB_API_PULL_BASE",
|
135
|
+
description: "The name of the branch to which changes should be pulled",
|
136
|
+
optional: true,
|
137
|
+
type: String),
|
138
|
+
FastlaneCore::ConfigItem.new(key: :maintainer_can_modify,
|
139
|
+
env_name: "GITHUB_API_PULL_MAINTAINER_CAN_MODIFY",
|
140
|
+
description: "Indicates whether maintainers can modify the pull request",
|
141
|
+
optional: true,
|
142
|
+
type: Boolean)
|
143
|
+
]
|
144
|
+
end
|
145
|
+
|
146
|
+
def output
|
147
|
+
[
|
148
|
+
['GITHUB_UPDATE_PULL_STATUS_CODE', 'The status code returned by the GitHub API'],
|
149
|
+
['GITHUB_UPDATE_PULL_RESPONSE', 'The full response body returned by the GitHub API'],
|
150
|
+
['GITHUB_UPDATE_PULL_JSON', 'The parsed JSON response returned by the GitHub API']
|
151
|
+
]
|
152
|
+
end
|
153
|
+
|
154
|
+
def return_value
|
155
|
+
"Returns a hash containing the status code, response body, and parsed JSON response from the GitHub API."
|
156
|
+
end
|
157
|
+
|
158
|
+
def authors
|
159
|
+
["crazymanish"]
|
160
|
+
end
|
161
|
+
|
162
|
+
def is_supported?(platform)
|
163
|
+
true
|
164
|
+
end
|
165
|
+
|
166
|
+
def example_code
|
167
|
+
[
|
168
|
+
'github_update_pull(
|
169
|
+
repo_owner: "octocat",
|
170
|
+
repo_name: "Hello-World",
|
171
|
+
pull_number: 42,
|
172
|
+
title: "New pull request title",
|
173
|
+
body: "Updated description",
|
174
|
+
state: "open"
|
175
|
+
)',
|
176
|
+
'updated_pull = github_update_pull(
|
177
|
+
repo_owner: "octocat",
|
178
|
+
repo_name: "Hello-World",
|
179
|
+
pull_number: 42,
|
180
|
+
title: "Updated title",
|
181
|
+
state: "closed"
|
182
|
+
)
|
183
|
+
|
184
|
+
title = updated_pull[:json]["title"]
|
185
|
+
puts "Updated Pull Request Title: #{title}"'
|
186
|
+
]
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
@@ -0,0 +1,158 @@
|
|
1
|
+
require 'fastlane/action'
|
2
|
+
require_relative '../helper/github_api_helper'
|
3
|
+
|
4
|
+
module Fastlane
|
5
|
+
module Actions
|
6
|
+
module SharedValues
|
7
|
+
GITHUB_UPDATE_PULL_BRANCH_STATUS_CODE = :GITHUB_UPDATE_PULL_BRANCH_STATUS_CODE
|
8
|
+
GITHUB_UPDATE_PULL_BRANCH_RESPONSE = :GITHUB_UPDATE_PULL_BRANCH_RESPONSE
|
9
|
+
GITHUB_UPDATE_PULL_BRANCH_JSON = :GITHUB_UPDATE_PULL_BRANCH_JSON
|
10
|
+
end
|
11
|
+
|
12
|
+
class GithubUpdatePullBranchAction < 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
|
+
expected_head_sha = params[:expected_head_sha]
|
24
|
+
|
25
|
+
# Build the body for the update request
|
26
|
+
body = {}
|
27
|
+
body[:expected_head_sha] = expected_head_sha if expected_head_sha
|
28
|
+
|
29
|
+
# Build the path
|
30
|
+
path = "/repos/#{repo_owner}/#{repo_name}/pulls/#{pull_number}/update-branch"
|
31
|
+
|
32
|
+
UI.message("Updating branch for pull request ##{pull_number} from #{repo_owner}/#{repo_name}")
|
33
|
+
response = Helper::GithubApiHelper.github_api_request(
|
34
|
+
token: api_token,
|
35
|
+
path: path,
|
36
|
+
params: body,
|
37
|
+
method: :put,
|
38
|
+
server_url: server_url
|
39
|
+
)
|
40
|
+
|
41
|
+
status_code = response[:status]
|
42
|
+
json_response = response[:json]
|
43
|
+
result = {
|
44
|
+
status: status_code,
|
45
|
+
body: response[:body],
|
46
|
+
json: json_response
|
47
|
+
}
|
48
|
+
|
49
|
+
if status_code.between?(200, 299)
|
50
|
+
UI.success("Successfully updated branch for pull request ##{pull_number} from #{repo_owner}/#{repo_name}")
|
51
|
+
else
|
52
|
+
UI.error("Error updating branch for pull request: #{status_code}")
|
53
|
+
UI.error(response[:body])
|
54
|
+
UI.user_error!("GitHub API returned #{status_code}: #{response[:body]}")
|
55
|
+
return nil
|
56
|
+
end
|
57
|
+
|
58
|
+
# Store the results in shared values
|
59
|
+
Actions.lane_context[SharedValues::GITHUB_UPDATE_PULL_BRANCH_STATUS_CODE] = status_code
|
60
|
+
Actions.lane_context[SharedValues::GITHUB_UPDATE_PULL_BRANCH_RESPONSE] = response[:body]
|
61
|
+
Actions.lane_context[SharedValues::GITHUB_UPDATE_PULL_BRANCH_JSON] = json_response
|
62
|
+
|
63
|
+
return result
|
64
|
+
end
|
65
|
+
|
66
|
+
#####################################################
|
67
|
+
# @!group Documentation
|
68
|
+
#####################################################
|
69
|
+
|
70
|
+
def description
|
71
|
+
"Updates a pull request branch with the latest upstream changes"
|
72
|
+
end
|
73
|
+
|
74
|
+
def details
|
75
|
+
[
|
76
|
+
"Updates the pull request branch with the latest upstream changes by merging head from the base branch.",
|
77
|
+
"You must provide your GitHub Personal token (get one from https://github.com/settings/tokens/new).",
|
78
|
+
"API Documentation: https://docs.github.com/en/rest/pulls/pulls#update-a-pull-request-branch"
|
79
|
+
].join("\n")
|
80
|
+
end
|
81
|
+
|
82
|
+
def available_options
|
83
|
+
[
|
84
|
+
FastlaneCore::ConfigItem.new(key: :api_token,
|
85
|
+
env_name: "GITHUB_API_TOKEN",
|
86
|
+
description: "GitHub API token",
|
87
|
+
optional: false,
|
88
|
+
sensitive: true,
|
89
|
+
code_gen_sensitive: true,
|
90
|
+
default_value: ENV["GITHUB_API_TOKEN"],
|
91
|
+
verify_block: proc do |value|
|
92
|
+
UI.user_error!("No GitHub API token given, pass using `api_token: 'token'`") if value.to_s.empty?
|
93
|
+
end),
|
94
|
+
FastlaneCore::ConfigItem.new(key: :server_url,
|
95
|
+
env_name: "GITHUB_API_SERVER_URL",
|
96
|
+
description: "GitHub API server URL",
|
97
|
+
optional: true,
|
98
|
+
default_value: "https://api.github.com"),
|
99
|
+
FastlaneCore::ConfigItem.new(key: :repo_owner,
|
100
|
+
env_name: "GITHUB_API_REPO_OWNER",
|
101
|
+
description: "Owner of the repository",
|
102
|
+
optional: false),
|
103
|
+
FastlaneCore::ConfigItem.new(key: :repo_name,
|
104
|
+
env_name: "GITHUB_API_REPO_NAME",
|
105
|
+
description: "Name of the repository",
|
106
|
+
optional: false),
|
107
|
+
FastlaneCore::ConfigItem.new(key: :pull_number,
|
108
|
+
env_name: "GITHUB_API_PULL_NUMBER",
|
109
|
+
description: "The number of the pull request",
|
110
|
+
optional: false,
|
111
|
+
type: Integer),
|
112
|
+
FastlaneCore::ConfigItem.new(key: :expected_head_sha,
|
113
|
+
env_name: "GITHUB_API_EXPECTED_HEAD_SHA",
|
114
|
+
description: "The expected SHA of the pull request's HEAD ref",
|
115
|
+
optional: true,
|
116
|
+
type: String)
|
117
|
+
]
|
118
|
+
end
|
119
|
+
|
120
|
+
def output
|
121
|
+
[
|
122
|
+
['GITHUB_UPDATE_PULL_BRANCH_STATUS_CODE', 'The status code returned by the GitHub API'],
|
123
|
+
['GITHUB_UPDATE_PULL_BRANCH_RESPONSE', 'The full response body returned by the GitHub API'],
|
124
|
+
['GITHUB_UPDATE_PULL_BRANCH_JSON', 'The parsed JSON response returned by the GitHub API']
|
125
|
+
]
|
126
|
+
end
|
127
|
+
|
128
|
+
def return_value
|
129
|
+
"Returns a hash containing the status code, response body, and parsed JSON response from the GitHub API."
|
130
|
+
end
|
131
|
+
|
132
|
+
def authors
|
133
|
+
["crazymanish"]
|
134
|
+
end
|
135
|
+
|
136
|
+
def is_supported?(platform)
|
137
|
+
true
|
138
|
+
end
|
139
|
+
|
140
|
+
def example_code
|
141
|
+
[
|
142
|
+
'github_update_pull_branch(
|
143
|
+
repo_owner: "octocat",
|
144
|
+
repo_name: "Hello-World",
|
145
|
+
pull_number: 42
|
146
|
+
)',
|
147
|
+
'github_update_pull_branch(
|
148
|
+
repo_owner: "octocat",
|
149
|
+
repo_name: "Hello-World",
|
150
|
+
pull_number: 42,
|
151
|
+
expected_head_sha: "6dcb09b5b57875f334f61aebed695e2e4193db5e"
|
152
|
+
)'
|
153
|
+
]
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
@@ -0,0 +1,156 @@
|
|
1
|
+
require 'fastlane/action'
|
2
|
+
require_relative '../helper/github_api_helper'
|
3
|
+
|
4
|
+
module Fastlane
|
5
|
+
module Actions
|
6
|
+
module SharedValues
|
7
|
+
GITHUB_UPDATE_PULL_COMMENT_STATUS_CODE = :GITHUB_UPDATE_PULL_COMMENT_STATUS_CODE
|
8
|
+
GITHUB_UPDATE_PULL_COMMENT_RESPONSE = :GITHUB_UPDATE_PULL_COMMENT_RESPONSE
|
9
|
+
GITHUB_UPDATE_PULL_COMMENT_JSON = :GITHUB_UPDATE_PULL_COMMENT_JSON
|
10
|
+
end
|
11
|
+
|
12
|
+
class GithubUpdatePullCommentAction < 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
|
+
comment_id = params[:comment_id]
|
23
|
+
|
24
|
+
# Validate required parameters
|
25
|
+
UI.user_error!("Comment body is required") if params[:body].to_s.empty?
|
26
|
+
|
27
|
+
# Build the path
|
28
|
+
path = "/repos/#{repo_owner}/#{repo_name}/pulls/comments/#{comment_id}"
|
29
|
+
|
30
|
+
# Build body parameters
|
31
|
+
body_params = {
|
32
|
+
body: params[:body]
|
33
|
+
}
|
34
|
+
|
35
|
+
UI.message("Updating pull request comment #{comment_id} in #{repo_owner}/#{repo_name}")
|
36
|
+
response = Helper::GithubApiHelper.github_api_request(
|
37
|
+
token: api_token,
|
38
|
+
path: path,
|
39
|
+
params: body_params,
|
40
|
+
method: :patch,
|
41
|
+
server_url: server_url
|
42
|
+
)
|
43
|
+
|
44
|
+
status_code = response[:status]
|
45
|
+
json_response = response[:json]
|
46
|
+
result = {
|
47
|
+
status: status_code,
|
48
|
+
body: response[:body],
|
49
|
+
json: json_response
|
50
|
+
}
|
51
|
+
|
52
|
+
if status_code.between?(200, 299)
|
53
|
+
UI.success("Successfully updated pull request comment #{comment_id}")
|
54
|
+
else
|
55
|
+
UI.error("Error updating pull request comment: #{status_code}")
|
56
|
+
UI.error(response[:body])
|
57
|
+
UI.user_error!("GitHub API returned #{status_code}: #{response[:body]}")
|
58
|
+
return nil
|
59
|
+
end
|
60
|
+
|
61
|
+
# Store the results in shared values
|
62
|
+
Actions.lane_context[SharedValues::GITHUB_UPDATE_PULL_COMMENT_STATUS_CODE] = status_code
|
63
|
+
Actions.lane_context[SharedValues::GITHUB_UPDATE_PULL_COMMENT_RESPONSE] = response[:body]
|
64
|
+
Actions.lane_context[SharedValues::GITHUB_UPDATE_PULL_COMMENT_JSON] = json_response
|
65
|
+
|
66
|
+
return result
|
67
|
+
end
|
68
|
+
|
69
|
+
#####################################################
|
70
|
+
# @!group Documentation
|
71
|
+
#####################################################
|
72
|
+
|
73
|
+
def description
|
74
|
+
"Updates a pull request comment"
|
75
|
+
end
|
76
|
+
|
77
|
+
def details
|
78
|
+
[
|
79
|
+
"Updates the body text of an existing review comment on a pull request.",
|
80
|
+
"You must provide your GitHub Personal token (get one from https://github.com/settings/tokens/new).",
|
81
|
+
"API Documentation: https://docs.github.com/en/rest/pulls/comments#update-a-review-comment-for-a-pull-request"
|
82
|
+
].join("\n")
|
83
|
+
end
|
84
|
+
|
85
|
+
def available_options
|
86
|
+
[
|
87
|
+
FastlaneCore::ConfigItem.new(key: :api_token,
|
88
|
+
env_name: "GITHUB_API_TOKEN",
|
89
|
+
description: "GitHub API token",
|
90
|
+
optional: false,
|
91
|
+
sensitive: true,
|
92
|
+
code_gen_sensitive: true,
|
93
|
+
default_value: ENV["GITHUB_API_TOKEN"],
|
94
|
+
verify_block: proc do |value|
|
95
|
+
UI.user_error!("No GitHub API token given, pass using `api_token: 'token'`") if value.to_s.empty?
|
96
|
+
end),
|
97
|
+
FastlaneCore::ConfigItem.new(key: :server_url,
|
98
|
+
env_name: "GITHUB_API_SERVER_URL",
|
99
|
+
description: "GitHub API server URL",
|
100
|
+
optional: true,
|
101
|
+
default_value: "https://api.github.com"),
|
102
|
+
FastlaneCore::ConfigItem.new(key: :repo_owner,
|
103
|
+
env_name: "GITHUB_API_REPO_OWNER",
|
104
|
+
description: "Owner of the repository",
|
105
|
+
optional: false),
|
106
|
+
FastlaneCore::ConfigItem.new(key: :repo_name,
|
107
|
+
env_name: "GITHUB_API_REPO_NAME",
|
108
|
+
description: "Name of the repository",
|
109
|
+
optional: false),
|
110
|
+
FastlaneCore::ConfigItem.new(key: :comment_id,
|
111
|
+
env_name: "GITHUB_API_PR_COMMENT_ID",
|
112
|
+
description: "The ID of the comment to update",
|
113
|
+
optional: false,
|
114
|
+
type: Integer),
|
115
|
+
FastlaneCore::ConfigItem.new(key: :body,
|
116
|
+
env_name: "GITHUB_API_PR_COMMENT_BODY",
|
117
|
+
description: "The new text of the comment",
|
118
|
+
optional: false,
|
119
|
+
type: String)
|
120
|
+
]
|
121
|
+
end
|
122
|
+
|
123
|
+
def output
|
124
|
+
[
|
125
|
+
['GITHUB_UPDATE_PULL_COMMENT_STATUS_CODE', 'The status code returned by the GitHub API'],
|
126
|
+
['GITHUB_UPDATE_PULL_COMMENT_RESPONSE', 'The full response body returned by the GitHub API'],
|
127
|
+
['GITHUB_UPDATE_PULL_COMMENT_JSON', 'The parsed JSON response returned by the GitHub API']
|
128
|
+
]
|
129
|
+
end
|
130
|
+
|
131
|
+
def return_value
|
132
|
+
"Returns a hash containing the status code, response body, and parsed JSON response from the GitHub API."
|
133
|
+
end
|
134
|
+
|
135
|
+
def authors
|
136
|
+
["crazymanish"]
|
137
|
+
end
|
138
|
+
|
139
|
+
def is_supported?(platform)
|
140
|
+
true
|
141
|
+
end
|
142
|
+
|
143
|
+
def example_code
|
144
|
+
[
|
145
|
+
'github_update_pull_comment(
|
146
|
+
repo_owner: "octocat",
|
147
|
+
repo_name: "Hello-World",
|
148
|
+
comment_id: 12345,
|
149
|
+
body: "Updated comment with more details about the implementation."
|
150
|
+
)'
|
151
|
+
]
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
@@ -0,0 +1,151 @@
|
|
1
|
+
require 'fastlane/action'
|
2
|
+
require_relative '../helper/github_api_helper'
|
3
|
+
|
4
|
+
module Fastlane
|
5
|
+
module Actions
|
6
|
+
module SharedValues
|
7
|
+
GITHUB_UPDATE_PULL_REVIEW_STATUS_CODE = :GITHUB_UPDATE_PULL_REVIEW_STATUS_CODE
|
8
|
+
GITHUB_UPDATE_PULL_REVIEW_RESPONSE = :GITHUB_UPDATE_PULL_REVIEW_RESPONSE
|
9
|
+
GITHUB_UPDATE_PULL_REVIEW_JSON = :GITHUB_UPDATE_PULL_REVIEW_JSON
|
10
|
+
end
|
11
|
+
|
12
|
+
class GithubUpdatePullReviewAction < 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
|
+
review_id = params[:review_id]
|
24
|
+
|
25
|
+
# Validate body parameter
|
26
|
+
UI.user_error!("Review body is required") if params[:body].to_s.empty?
|
27
|
+
|
28
|
+
# Build the path
|
29
|
+
path = "/repos/#{repo_owner}/#{repo_name}/pulls/#{pull_number}/reviews/#{review_id}"
|
30
|
+
|
31
|
+
# Build body parameters
|
32
|
+
body_params = {
|
33
|
+
body: params[:body]
|
34
|
+
}
|
35
|
+
|
36
|
+
UI.message("Updating review #{review_id} for pull request ##{pull_number} in #{repo_owner}/#{repo_name}")
|
37
|
+
response = Helper::GithubApiHelper.github_api_request(
|
38
|
+
token: api_token,
|
39
|
+
path: path,
|
40
|
+
params: body_params,
|
41
|
+
method: :put,
|
42
|
+
server_url: server_url
|
43
|
+
)
|
44
|
+
|
45
|
+
status_code = response[:status]
|
46
|
+
json_response = response[:json]
|
47
|
+
result = {
|
48
|
+
status: status_code,
|
49
|
+
body: response[:body],
|
50
|
+
json: json_response
|
51
|
+
}
|
52
|
+
|
53
|
+
if status_code.between?(200, 299)
|
54
|
+
UI.success("Successfully updated review #{review_id} for pull request ##{pull_number}")
|
55
|
+
else
|
56
|
+
UI.error("Error updating pull request review: #{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_UPDATE_PULL_REVIEW_STATUS_CODE] = status_code
|
64
|
+
Actions.lane_context[SharedValues::GITHUB_UPDATE_PULL_REVIEW_RESPONSE] = response[:body]
|
65
|
+
Actions.lane_context[SharedValues::GITHUB_UPDATE_PULL_REVIEW_JSON] = json_response
|
66
|
+
|
67
|
+
return result
|
68
|
+
end
|
69
|
+
|
70
|
+
#####################################################
|
71
|
+
# @!group Documentation
|
72
|
+
#####################################################
|
73
|
+
|
74
|
+
def description
|
75
|
+
"Updates a review for a pull request"
|
76
|
+
end
|
77
|
+
|
78
|
+
def details
|
79
|
+
[
|
80
|
+
"Updates the body text of a review. Only the body can be updated.",
|
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/reviews#update-a-review-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: :review_id,
|
117
|
+
env_name: "GITHUB_API_REVIEW_ID",
|
118
|
+
description: "The ID of the review",
|
119
|
+
optional: false,
|
120
|
+
type: Integer),
|
121
|
+
FastlaneCore::ConfigItem.new(key: :body,
|
122
|
+
env_name: "GITHUB_API_REVIEW_BODY",
|
123
|
+
description: "The updated body text of the review",
|
124
|
+
optional: false,
|
125
|
+
type: String)
|
126
|
+
]
|
127
|
+
end
|
128
|
+
|
129
|
+
def output
|
130
|
+
[
|
131
|
+
['GITHUB_UPDATE_PULL_REVIEW_STATUS_CODE', 'The status code returned by the GitHub API'],
|
132
|
+
['GITHUB_UPDATE_PULL_REVIEW_RESPONSE', 'The full response body returned by the GitHub API'],
|
133
|
+
['GITHUB_UPDATE_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
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|