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,175 @@
|
|
1
|
+
require 'fastlane/action'
|
2
|
+
require_relative '../helper/github_api_helper'
|
3
|
+
|
4
|
+
module Fastlane
|
5
|
+
module Actions
|
6
|
+
module SharedValues
|
7
|
+
GITHUB_LIST_PULL_COMMITS_STATUS_CODE = :GITHUB_LIST_PULL_COMMITS_STATUS_CODE
|
8
|
+
GITHUB_LIST_PULL_COMMITS_RESPONSE = :GITHUB_LIST_PULL_COMMITS_RESPONSE
|
9
|
+
GITHUB_LIST_PULL_COMMITS_JSON = :GITHUB_LIST_PULL_COMMITS_JSON
|
10
|
+
end
|
11
|
+
|
12
|
+
class GithubListPullCommitsAction < 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
|
+
per_page = params[:per_page]
|
24
|
+
page = params[:page]
|
25
|
+
|
26
|
+
# Build query parameters
|
27
|
+
query_params = {}
|
28
|
+
query_params[:per_page] = per_page if per_page
|
29
|
+
query_params[:page] = page if page
|
30
|
+
|
31
|
+
# Build the path
|
32
|
+
path = "/repos/#{repo_owner}/#{repo_name}/pulls/#{pull_number}/commits"
|
33
|
+
|
34
|
+
UI.message("Getting commits 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: query_params.empty? ? nil : query_params,
|
39
|
+
method: :get,
|
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
|
+
commit_count = json_response.is_a?(Array) ? json_response.count : 0
|
53
|
+
UI.success("Successfully retrieved #{commit_count} commits for pull request ##{pull_number} from #{repo_owner}/#{repo_name}")
|
54
|
+
else
|
55
|
+
UI.error("Error getting pull request commits: #{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_LIST_PULL_COMMITS_STATUS_CODE] = status_code
|
63
|
+
Actions.lane_context[SharedValues::GITHUB_LIST_PULL_COMMITS_RESPONSE] = response[:body]
|
64
|
+
Actions.lane_context[SharedValues::GITHUB_LIST_PULL_COMMITS_JSON] = json_response
|
65
|
+
|
66
|
+
return result
|
67
|
+
end
|
68
|
+
|
69
|
+
#####################################################
|
70
|
+
# @!group Documentation
|
71
|
+
#####################################################
|
72
|
+
|
73
|
+
def description
|
74
|
+
"Lists commits on a pull request"
|
75
|
+
end
|
76
|
+
|
77
|
+
def details
|
78
|
+
[
|
79
|
+
"Lists commits on a 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#list-commits-on-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: :per_page,
|
116
|
+
env_name: "GITHUB_API_PER_PAGE",
|
117
|
+
description: "Results per page (max 100)",
|
118
|
+
optional: true,
|
119
|
+
type: Integer),
|
120
|
+
FastlaneCore::ConfigItem.new(key: :page,
|
121
|
+
env_name: "GITHUB_API_PAGE",
|
122
|
+
description: "Page number of the results to fetch",
|
123
|
+
optional: true,
|
124
|
+
type: Integer)
|
125
|
+
]
|
126
|
+
end
|
127
|
+
|
128
|
+
def output
|
129
|
+
[
|
130
|
+
['GITHUB_LIST_PULL_COMMITS_STATUS_CODE', 'The status code returned by the GitHub API'],
|
131
|
+
['GITHUB_LIST_PULL_COMMITS_RESPONSE', 'The full response body returned by the GitHub API'],
|
132
|
+
['GITHUB_LIST_PULL_COMMITS_JSON', 'The parsed JSON response returned by the GitHub API']
|
133
|
+
]
|
134
|
+
end
|
135
|
+
|
136
|
+
def return_value
|
137
|
+
"Returns a hash containing the status code, response body, and parsed JSON response from the GitHub API."
|
138
|
+
end
|
139
|
+
|
140
|
+
def authors
|
141
|
+
["crazymanish"]
|
142
|
+
end
|
143
|
+
|
144
|
+
def is_supported?(platform)
|
145
|
+
true
|
146
|
+
end
|
147
|
+
|
148
|
+
def example_code
|
149
|
+
[
|
150
|
+
'github_list_pull_commits(
|
151
|
+
repo_owner: "octocat",
|
152
|
+
repo_name: "Hello-World",
|
153
|
+
pull_number: 42
|
154
|
+
)',
|
155
|
+
'pull_commits = github_list_pull_commits(
|
156
|
+
repo_owner: "octocat",
|
157
|
+
repo_name: "Hello-World",
|
158
|
+
pull_number: 42,
|
159
|
+
per_page: 30,
|
160
|
+
page: 1
|
161
|
+
)
|
162
|
+
|
163
|
+
commits = pull_commits[:json]
|
164
|
+
commits.each do |commit|
|
165
|
+
puts "Commit SHA: #{commit["sha"]}"
|
166
|
+
puts "Author: #{commit["commit"]["author"]["name"]}"
|
167
|
+
puts "Message: #{commit["commit"]["message"]}"
|
168
|
+
puts "---"
|
169
|
+
end'
|
170
|
+
]
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
@@ -0,0 +1,174 @@
|
|
1
|
+
require 'fastlane/action'
|
2
|
+
require_relative '../helper/github_api_helper'
|
3
|
+
|
4
|
+
module Fastlane
|
5
|
+
module Actions
|
6
|
+
module SharedValues
|
7
|
+
GITHUB_LIST_PULL_FILES_STATUS_CODE = :GITHUB_LIST_PULL_FILES_STATUS_CODE
|
8
|
+
GITHUB_LIST_PULL_FILES_RESPONSE = :GITHUB_LIST_PULL_FILES_RESPONSE
|
9
|
+
GITHUB_LIST_PULL_FILES_JSON = :GITHUB_LIST_PULL_FILES_JSON
|
10
|
+
end
|
11
|
+
|
12
|
+
class GithubListPullFilesAction < 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
|
+
per_page = params[:per_page]
|
24
|
+
page = params[:page]
|
25
|
+
|
26
|
+
# Build query parameters
|
27
|
+
query_params = {}
|
28
|
+
query_params[:per_page] = per_page if per_page
|
29
|
+
query_params[:page] = page if page
|
30
|
+
|
31
|
+
# Build the path
|
32
|
+
path = "/repos/#{repo_owner}/#{repo_name}/pulls/#{pull_number}/files"
|
33
|
+
|
34
|
+
UI.message("Listing files 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: query_params.empty? ? nil : query_params,
|
39
|
+
method: :get,
|
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
|
+
file_count = json_response.is_a?(Array) ? json_response.count : 0
|
53
|
+
UI.success("Successfully retrieved #{file_count} files for pull request ##{pull_number}")
|
54
|
+
else
|
55
|
+
UI.error("Error listing pull request files: #{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_LIST_PULL_FILES_STATUS_CODE] = status_code
|
63
|
+
Actions.lane_context[SharedValues::GITHUB_LIST_PULL_FILES_RESPONSE] = response[:body]
|
64
|
+
Actions.lane_context[SharedValues::GITHUB_LIST_PULL_FILES_JSON] = json_response
|
65
|
+
|
66
|
+
return result
|
67
|
+
end
|
68
|
+
|
69
|
+
#####################################################
|
70
|
+
# @!group Documentation
|
71
|
+
#####################################################
|
72
|
+
|
73
|
+
def description
|
74
|
+
"List files in a pull request"
|
75
|
+
end
|
76
|
+
|
77
|
+
def details
|
78
|
+
[
|
79
|
+
"Lists all files changed in 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/pulls#list-pull-requests-files"
|
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: :per_page,
|
116
|
+
env_name: "GITHUB_API_PER_PAGE",
|
117
|
+
description: "Results per page (max 100)",
|
118
|
+
optional: true,
|
119
|
+
type: Integer),
|
120
|
+
FastlaneCore::ConfigItem.new(key: :page,
|
121
|
+
env_name: "GITHUB_API_PAGE",
|
122
|
+
description: "Page number of the results to fetch",
|
123
|
+
optional: true,
|
124
|
+
type: Integer)
|
125
|
+
]
|
126
|
+
end
|
127
|
+
|
128
|
+
def output
|
129
|
+
[
|
130
|
+
['GITHUB_LIST_PULL_FILES_STATUS_CODE', 'The status code returned by the GitHub API'],
|
131
|
+
['GITHUB_LIST_PULL_FILES_RESPONSE', 'The full response body returned by the GitHub API'],
|
132
|
+
['GITHUB_LIST_PULL_FILES_JSON', 'The parsed JSON response returned by the GitHub API']
|
133
|
+
]
|
134
|
+
end
|
135
|
+
|
136
|
+
def return_value
|
137
|
+
"Returns a hash containing the status code, response body, and parsed JSON response from the GitHub API."
|
138
|
+
end
|
139
|
+
|
140
|
+
def authors
|
141
|
+
["crazymanish"]
|
142
|
+
end
|
143
|
+
|
144
|
+
def is_supported?(platform)
|
145
|
+
true
|
146
|
+
end
|
147
|
+
|
148
|
+
def example_code
|
149
|
+
[
|
150
|
+
'github_list_pull_files(
|
151
|
+
repo_owner: "octocat",
|
152
|
+
repo_name: "Hello-World",
|
153
|
+
pull_number: 42
|
154
|
+
)',
|
155
|
+
'files = github_list_pull_files(
|
156
|
+
repo_owner: "octocat",
|
157
|
+
repo_name: "Hello-World",
|
158
|
+
pull_number: 42,
|
159
|
+
per_page: 50,
|
160
|
+
page: 1
|
161
|
+
)
|
162
|
+
|
163
|
+
files[:json].each do |file|
|
164
|
+
puts "File: #{file["filename"]}"
|
165
|
+
puts "Status: #{file["status"]}"
|
166
|
+
puts "Additions: #{file["additions"]}, Deletions: #{file["deletions"]}, Changes: #{file["changes"]}"
|
167
|
+
puts "---"
|
168
|
+
end'
|
169
|
+
]
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
@@ -0,0 +1,163 @@
|
|
1
|
+
require 'fastlane/action'
|
2
|
+
require_relative '../helper/github_api_helper'
|
3
|
+
|
4
|
+
module Fastlane
|
5
|
+
module Actions
|
6
|
+
module SharedValues
|
7
|
+
GITHUB_LIST_PULL_REVIEWERS_STATUS_CODE = :GITHUB_LIST_PULL_REVIEWERS_STATUS_CODE
|
8
|
+
GITHUB_LIST_PULL_REVIEWERS_RESPONSE = :GITHUB_LIST_PULL_REVIEWERS_RESPONSE
|
9
|
+
GITHUB_LIST_PULL_REVIEWERS_JSON = :GITHUB_LIST_PULL_REVIEWERS_JSON
|
10
|
+
end
|
11
|
+
|
12
|
+
class GithubListPullReviewersAction < 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 path
|
25
|
+
path = "/repos/#{repo_owner}/#{repo_name}/pulls/#{pull_number}/requested_reviewers"
|
26
|
+
|
27
|
+
UI.message("Listing requested reviewers for pull request ##{pull_number} in #{repo_owner}/#{repo_name}")
|
28
|
+
response = Helper::GithubApiHelper.github_api_request(
|
29
|
+
token: api_token,
|
30
|
+
path: path,
|
31
|
+
method: :get,
|
32
|
+
server_url: server_url
|
33
|
+
)
|
34
|
+
|
35
|
+
status_code = response[:status]
|
36
|
+
json_response = response[:json]
|
37
|
+
result = {
|
38
|
+
status: status_code,
|
39
|
+
body: response[:body],
|
40
|
+
json: json_response
|
41
|
+
}
|
42
|
+
|
43
|
+
if status_code.between?(200, 299)
|
44
|
+
reviewers_count = 0
|
45
|
+
team_reviewers_count = 0
|
46
|
+
|
47
|
+
if json_response["users"] && json_response["users"].is_a?(Array)
|
48
|
+
reviewers_count = json_response["users"].count
|
49
|
+
end
|
50
|
+
|
51
|
+
if json_response["teams"] && json_response["teams"].is_a?(Array)
|
52
|
+
team_reviewers_count = json_response["teams"].count
|
53
|
+
end
|
54
|
+
|
55
|
+
UI.success("Successfully listed #{reviewers_count} reviewers and #{team_reviewers_count} team reviewers for pull request ##{pull_number}")
|
56
|
+
else
|
57
|
+
UI.error("Error listing reviewers: #{status_code}")
|
58
|
+
UI.error(response[:body])
|
59
|
+
UI.user_error!("GitHub API returned #{status_code}: #{response[:body]}")
|
60
|
+
return nil
|
61
|
+
end
|
62
|
+
|
63
|
+
# Store the results in shared values
|
64
|
+
Actions.lane_context[SharedValues::GITHUB_LIST_PULL_REVIEWERS_STATUS_CODE] = status_code
|
65
|
+
Actions.lane_context[SharedValues::GITHUB_LIST_PULL_REVIEWERS_RESPONSE] = response[:body]
|
66
|
+
Actions.lane_context[SharedValues::GITHUB_LIST_PULL_REVIEWERS_JSON] = json_response
|
67
|
+
|
68
|
+
return result
|
69
|
+
end
|
70
|
+
|
71
|
+
#####################################################
|
72
|
+
# @!group Documentation
|
73
|
+
#####################################################
|
74
|
+
|
75
|
+
def description
|
76
|
+
"Lists requested reviewers for a pull request"
|
77
|
+
end
|
78
|
+
|
79
|
+
def details
|
80
|
+
[
|
81
|
+
"Lists all requested reviewers for a pull request.",
|
82
|
+
"You must provide your GitHub Personal token (get one from https://github.com/settings/tokens/new).",
|
83
|
+
"API Documentation: https://docs.github.com/en/rest/pulls/review-requests#get-all-requested-reviewers-for-a-pull-request"
|
84
|
+
].join("\n")
|
85
|
+
end
|
86
|
+
|
87
|
+
def available_options
|
88
|
+
[
|
89
|
+
FastlaneCore::ConfigItem.new(key: :api_token,
|
90
|
+
env_name: "GITHUB_API_TOKEN",
|
91
|
+
description: "GitHub API token",
|
92
|
+
optional: false,
|
93
|
+
sensitive: true,
|
94
|
+
code_gen_sensitive: true,
|
95
|
+
default_value: ENV["GITHUB_API_TOKEN"],
|
96
|
+
verify_block: proc do |value|
|
97
|
+
UI.user_error!("No GitHub API token given, pass using `api_token: 'token'`") if value.to_s.empty?
|
98
|
+
end),
|
99
|
+
FastlaneCore::ConfigItem.new(key: :server_url,
|
100
|
+
env_name: "GITHUB_API_SERVER_URL",
|
101
|
+
description: "GitHub API server URL",
|
102
|
+
optional: true,
|
103
|
+
default_value: "https://api.github.com"),
|
104
|
+
FastlaneCore::ConfigItem.new(key: :repo_owner,
|
105
|
+
env_name: "GITHUB_API_REPO_OWNER",
|
106
|
+
description: "Owner of the repository",
|
107
|
+
optional: false),
|
108
|
+
FastlaneCore::ConfigItem.new(key: :repo_name,
|
109
|
+
env_name: "GITHUB_API_REPO_NAME",
|
110
|
+
description: "Name of the repository",
|
111
|
+
optional: false),
|
112
|
+
FastlaneCore::ConfigItem.new(key: :pull_number,
|
113
|
+
env_name: "GITHUB_API_PULL_NUMBER",
|
114
|
+
description: "The number of the pull request",
|
115
|
+
optional: false,
|
116
|
+
type: Integer)
|
117
|
+
]
|
118
|
+
end
|
119
|
+
|
120
|
+
def output
|
121
|
+
[
|
122
|
+
['GITHUB_LIST_PULL_REVIEWERS_STATUS_CODE', 'The status code returned by the GitHub API'],
|
123
|
+
['GITHUB_LIST_PULL_REVIEWERS_RESPONSE', 'The full response body returned by the GitHub API'],
|
124
|
+
['GITHUB_LIST_PULL_REVIEWERS_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_list_pull_reviewers(
|
143
|
+
repo_owner: "octocat",
|
144
|
+
repo_name: "Hello-World",
|
145
|
+
pull_number: 42
|
146
|
+
)',
|
147
|
+
'reviewers_info = github_list_pull_reviewers(
|
148
|
+
repo_owner: "octocat",
|
149
|
+
repo_name: "Hello-World",
|
150
|
+
pull_number: 42
|
151
|
+
)
|
152
|
+
|
153
|
+
users = reviewers_info[:json]["users"]
|
154
|
+
teams = reviewers_info[:json]["teams"]
|
155
|
+
|
156
|
+
puts "Requested reviewers: #{users.map { |u| u["login"] }.join(", ")}"
|
157
|
+
puts "Requested team reviewers: #{teams.map { |t| t["name"] }.join(", ")}"'
|
158
|
+
]
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
@@ -0,0 +1,175 @@
|
|
1
|
+
require 'fastlane/action'
|
2
|
+
require_relative '../helper/github_api_helper'
|
3
|
+
|
4
|
+
module Fastlane
|
5
|
+
module Actions
|
6
|
+
module SharedValues
|
7
|
+
GITHUB_LIST_PULL_REVIEWS_STATUS_CODE = :GITHUB_LIST_PULL_REVIEWS_STATUS_CODE
|
8
|
+
GITHUB_LIST_PULL_REVIEWS_RESPONSE = :GITHUB_LIST_PULL_REVIEWS_RESPONSE
|
9
|
+
GITHUB_LIST_PULL_REVIEWS_JSON = :GITHUB_LIST_PULL_REVIEWS_JSON
|
10
|
+
end
|
11
|
+
|
12
|
+
class GithubListPullReviewsAction < 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
|
+
per_page = params[:per_page]
|
24
|
+
page = params[:page]
|
25
|
+
|
26
|
+
# Build query parameters
|
27
|
+
query_params = {}
|
28
|
+
query_params[:per_page] = per_page if per_page
|
29
|
+
query_params[:page] = page if page
|
30
|
+
|
31
|
+
# Build the path
|
32
|
+
path = "/repos/#{repo_owner}/#{repo_name}/pulls/#{pull_number}/reviews"
|
33
|
+
|
34
|
+
UI.message("Listing reviews 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: query_params.empty? ? nil : query_params,
|
39
|
+
method: :get,
|
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
|
+
review_count = json_response.is_a?(Array) ? json_response.count : 0
|
53
|
+
UI.success("Successfully retrieved #{review_count} reviews for pull request ##{pull_number}")
|
54
|
+
else
|
55
|
+
UI.error("Error listing pull request reviews: #{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_LIST_PULL_REVIEWS_STATUS_CODE] = status_code
|
63
|
+
Actions.lane_context[SharedValues::GITHUB_LIST_PULL_REVIEWS_RESPONSE] = response[:body]
|
64
|
+
Actions.lane_context[SharedValues::GITHUB_LIST_PULL_REVIEWS_JSON] = json_response
|
65
|
+
|
66
|
+
return result
|
67
|
+
end
|
68
|
+
|
69
|
+
#####################################################
|
70
|
+
# @!group Documentation
|
71
|
+
#####################################################
|
72
|
+
|
73
|
+
def description
|
74
|
+
"List reviews for a pull request"
|
75
|
+
end
|
76
|
+
|
77
|
+
def details
|
78
|
+
[
|
79
|
+
"Lists all reviews for 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/reviews#list-reviews-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: :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: :per_page,
|
116
|
+
env_name: "GITHUB_API_PER_PAGE",
|
117
|
+
description: "Results per page (max 100)",
|
118
|
+
optional: true,
|
119
|
+
type: Integer),
|
120
|
+
FastlaneCore::ConfigItem.new(key: :page,
|
121
|
+
env_name: "GITHUB_API_PAGE",
|
122
|
+
description: "Page number of the results to fetch",
|
123
|
+
optional: true,
|
124
|
+
type: Integer)
|
125
|
+
]
|
126
|
+
end
|
127
|
+
|
128
|
+
def output
|
129
|
+
[
|
130
|
+
['GITHUB_LIST_PULL_REVIEWS_STATUS_CODE', 'The status code returned by the GitHub API'],
|
131
|
+
['GITHUB_LIST_PULL_REVIEWS_RESPONSE', 'The full response body returned by the GitHub API'],
|
132
|
+
['GITHUB_LIST_PULL_REVIEWS_JSON', 'The parsed JSON response returned by the GitHub API']
|
133
|
+
]
|
134
|
+
end
|
135
|
+
|
136
|
+
def return_value
|
137
|
+
"Returns a hash containing the status code, response body, and parsed JSON response from the GitHub API."
|
138
|
+
end
|
139
|
+
|
140
|
+
def authors
|
141
|
+
["crazymanish"]
|
142
|
+
end
|
143
|
+
|
144
|
+
def is_supported?(platform)
|
145
|
+
true
|
146
|
+
end
|
147
|
+
|
148
|
+
def example_code
|
149
|
+
[
|
150
|
+
'github_list_pull_reviews(
|
151
|
+
repo_owner: "octocat",
|
152
|
+
repo_name: "Hello-World",
|
153
|
+
pull_number: 42
|
154
|
+
)',
|
155
|
+
'reviews = github_list_pull_reviews(
|
156
|
+
repo_owner: "octocat",
|
157
|
+
repo_name: "Hello-World",
|
158
|
+
pull_number: 42,
|
159
|
+
per_page: 20,
|
160
|
+
page: 1
|
161
|
+
)
|
162
|
+
|
163
|
+
reviews[:json].each do |review|
|
164
|
+
puts "Review by #{review["user"]["login"]}"
|
165
|
+
puts "State: #{review["state"]}"
|
166
|
+
puts "Submitted at: #{review["submitted_at"]}"
|
167
|
+
puts "Body: #{review["body"]}"
|
168
|
+
puts "---"
|
169
|
+
end'
|
170
|
+
]
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|