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,168 @@
|
|
1
|
+
require 'fastlane/action'
|
2
|
+
require_relative '../helper/github_api_helper'
|
3
|
+
|
4
|
+
module Fastlane
|
5
|
+
module Actions
|
6
|
+
module SharedValues
|
7
|
+
GITHUB_CREATE_ISSUE_REACTION_STATUS_CODE = :GITHUB_CREATE_ISSUE_REACTION_STATUS_CODE
|
8
|
+
GITHUB_CREATE_ISSUE_REACTION_RESPONSE = :GITHUB_CREATE_ISSUE_REACTION_RESPONSE
|
9
|
+
GITHUB_CREATE_ISSUE_REACTION_JSON = :GITHUB_CREATE_ISSUE_REACTION_JSON
|
10
|
+
end
|
11
|
+
|
12
|
+
class GithubCreateIssueReactionAction < 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
|
+
issue_number = params[:issue_number]
|
23
|
+
content = params[:content]
|
24
|
+
|
25
|
+
# Build the request body
|
26
|
+
body = {
|
27
|
+
content: content
|
28
|
+
}
|
29
|
+
|
30
|
+
# Build the path
|
31
|
+
path = "/repos/#{repo_owner}/#{repo_name}/issues/#{issue_number}/reactions"
|
32
|
+
|
33
|
+
UI.message("Creating '#{content}' reaction for issue ##{issue_number} in #{repo_owner}/#{repo_name}")
|
34
|
+
response = Helper::GithubApiHelper.github_api_request(
|
35
|
+
token: api_token,
|
36
|
+
path: path,
|
37
|
+
params: body,
|
38
|
+
method: :post,
|
39
|
+
server_url: server_url,
|
40
|
+
headers: { 'Accept' => 'application/vnd.github.squirrel-girl-preview+json' }
|
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
|
+
UI.success("Successfully created '#{content}' reaction for issue ##{issue_number}")
|
53
|
+
else
|
54
|
+
UI.error("Error creating reaction: #{status_code}")
|
55
|
+
UI.error(response[:body])
|
56
|
+
UI.user_error!("GitHub API returned #{status_code}: #{response[:body]}")
|
57
|
+
return nil
|
58
|
+
end
|
59
|
+
|
60
|
+
# Store the results in shared values
|
61
|
+
Actions.lane_context[SharedValues::GITHUB_CREATE_ISSUE_REACTION_STATUS_CODE] = status_code
|
62
|
+
Actions.lane_context[SharedValues::GITHUB_CREATE_ISSUE_REACTION_RESPONSE] = response[:body]
|
63
|
+
Actions.lane_context[SharedValues::GITHUB_CREATE_ISSUE_REACTION_JSON] = json_response
|
64
|
+
|
65
|
+
return result
|
66
|
+
end
|
67
|
+
|
68
|
+
#####################################################
|
69
|
+
# @!group Documentation
|
70
|
+
#####################################################
|
71
|
+
|
72
|
+
def description
|
73
|
+
"Create a reaction for an issue"
|
74
|
+
end
|
75
|
+
|
76
|
+
def details
|
77
|
+
[
|
78
|
+
"Creates a reaction for an issue.",
|
79
|
+
"You must provide your GitHub Personal token (get one from https://github.com/settings/tokens/new).",
|
80
|
+
"API Documentation: https://docs.github.com/en/rest/reactions/reactions#create-reaction-for-an-issue"
|
81
|
+
].join("\n")
|
82
|
+
end
|
83
|
+
|
84
|
+
def available_options
|
85
|
+
[
|
86
|
+
FastlaneCore::ConfigItem.new(key: :api_token,
|
87
|
+
env_name: "GITHUB_API_TOKEN",
|
88
|
+
description: "GitHub API token",
|
89
|
+
optional: false,
|
90
|
+
sensitive: true,
|
91
|
+
code_gen_sensitive: true,
|
92
|
+
default_value: ENV["GITHUB_API_TOKEN"],
|
93
|
+
verify_block: proc do |value|
|
94
|
+
UI.user_error!("No GitHub API token given, pass using `api_token: 'token'`") if value.to_s.empty?
|
95
|
+
end),
|
96
|
+
FastlaneCore::ConfigItem.new(key: :server_url,
|
97
|
+
env_name: "GITHUB_API_SERVER_URL",
|
98
|
+
description: "GitHub API server URL",
|
99
|
+
optional: true,
|
100
|
+
default_value: "https://api.github.com"),
|
101
|
+
FastlaneCore::ConfigItem.new(key: :repo_owner,
|
102
|
+
env_name: "GITHUB_API_REPO_OWNER",
|
103
|
+
description: "Owner of the repository",
|
104
|
+
optional: false),
|
105
|
+
FastlaneCore::ConfigItem.new(key: :repo_name,
|
106
|
+
env_name: "GITHUB_API_REPO_NAME",
|
107
|
+
description: "Name of the repository",
|
108
|
+
optional: false),
|
109
|
+
FastlaneCore::ConfigItem.new(key: :issue_number,
|
110
|
+
env_name: "GITHUB_API_ISSUE_NUMBER",
|
111
|
+
description: "The number of the issue",
|
112
|
+
optional: false,
|
113
|
+
type: Integer),
|
114
|
+
FastlaneCore::ConfigItem.new(key: :content,
|
115
|
+
env_name: "GITHUB_API_REACTION_CONTENT",
|
116
|
+
description: "The reaction type (+1, -1, laugh, confused, heart, hooray, rocket, eyes)",
|
117
|
+
optional: false,
|
118
|
+
type: String,
|
119
|
+
verify_block: proc do |value|
|
120
|
+
valid_reactions = ['+1', '-1', 'laugh', 'confused', 'heart', 'hooray', 'rocket', 'eyes']
|
121
|
+
UI.user_error!("Invalid reaction content: '#{value}'. Must be one of: #{valid_reactions.join(', ')}") unless valid_reactions.include?(value)
|
122
|
+
end)
|
123
|
+
]
|
124
|
+
end
|
125
|
+
|
126
|
+
def output
|
127
|
+
[
|
128
|
+
['GITHUB_CREATE_ISSUE_REACTION_STATUS_CODE', 'The status code returned by the GitHub API'],
|
129
|
+
['GITHUB_CREATE_ISSUE_REACTION_RESPONSE', 'The full response body returned by the GitHub API'],
|
130
|
+
['GITHUB_CREATE_ISSUE_REACTION_JSON', 'The parsed JSON response returned by the GitHub API']
|
131
|
+
]
|
132
|
+
end
|
133
|
+
|
134
|
+
def return_value
|
135
|
+
"Returns a hash containing the status code, response body, and parsed JSON response from the GitHub API."
|
136
|
+
end
|
137
|
+
|
138
|
+
def authors
|
139
|
+
["crazymanish"]
|
140
|
+
end
|
141
|
+
|
142
|
+
def is_supported?(platform)
|
143
|
+
true
|
144
|
+
end
|
145
|
+
|
146
|
+
def example_code
|
147
|
+
[
|
148
|
+
'github_create_issue_reaction(
|
149
|
+
repo_owner: "octocat",
|
150
|
+
repo_name: "Hello-World",
|
151
|
+
issue_number: 123,
|
152
|
+
content: "+1"
|
153
|
+
)',
|
154
|
+
'reaction = github_create_issue_reaction(
|
155
|
+
repo_owner: "octocat",
|
156
|
+
repo_name: "Hello-World",
|
157
|
+
issue_number: 123,
|
158
|
+
content: "heart"
|
159
|
+
)
|
160
|
+
|
161
|
+
puts "Created reaction: #{reaction[:json]["content"]}"
|
162
|
+
puts "Reaction ID: #{reaction[:json]["id"]}"'
|
163
|
+
]
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
@@ -0,0 +1,194 @@
|
|
1
|
+
require 'fastlane/action'
|
2
|
+
require_relative '../helper/github_api_helper'
|
3
|
+
|
4
|
+
module Fastlane
|
5
|
+
module Actions
|
6
|
+
module SharedValues
|
7
|
+
GITHUB_CREATE_LABEL_RESPONSE = :GITHUB_CREATE_LABEL_RESPONSE
|
8
|
+
GITHUB_CREATE_LABEL_JSON = :GITHUB_CREATE_LABEL_JSON
|
9
|
+
GITHUB_CREATE_LABEL_STATUS_CODE = :GITHUB_CREATE_LABEL_STATUS_CODE
|
10
|
+
end
|
11
|
+
|
12
|
+
class GithubCreateLabelAction < 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
|
+
server_url = params[:server_url]
|
19
|
+
|
20
|
+
# Validate parameters (additional validation beyond what's in ConfigItem)
|
21
|
+
UI.user_error!("No label name provided, pass using `name: 'bug'`") if params[:name].to_s.empty?
|
22
|
+
UI.user_error!("No color provided, pass using `color: 'ff0000'`") if params[:color].to_s.empty?
|
23
|
+
|
24
|
+
# Prepare request parameters
|
25
|
+
path = "/repos/#{repo_owner}/#{repo_name}/labels"
|
26
|
+
|
27
|
+
# Build body parameters
|
28
|
+
body_params = {
|
29
|
+
name: params[:name],
|
30
|
+
color: params[:color].start_with?('#') ? params[:color][1..-1] : params[:color]
|
31
|
+
}
|
32
|
+
|
33
|
+
body_params[:description] = params[:description] if params[:description]
|
34
|
+
|
35
|
+
# Make the request
|
36
|
+
UI.message("Creating label '#{params[:name]}' in #{repo_owner}/#{repo_name}")
|
37
|
+
response = Helper::GithubApiHelper.github_api_request(
|
38
|
+
token: token,
|
39
|
+
path: path,
|
40
|
+
params: body_params,
|
41
|
+
method: :post,
|
42
|
+
server_url: server_url
|
43
|
+
)
|
44
|
+
|
45
|
+
status_code = response.key?('status') ? response['status'] : nil
|
46
|
+
result = {
|
47
|
+
status: status_code,
|
48
|
+
body: response,
|
49
|
+
json: response
|
50
|
+
}
|
51
|
+
|
52
|
+
if response.key?('error')
|
53
|
+
UI.error("GitHub responded with an error: #{response['error']}")
|
54
|
+
UI.user_error!("GitHub API error: #{response['error']}")
|
55
|
+
return nil
|
56
|
+
end
|
57
|
+
|
58
|
+
if response['message'] && status_code && status_code >= 400
|
59
|
+
UI.error("GitHub API error: #{response['message']}")
|
60
|
+
UI.user_error!("GitHub API error: #{response['message']} (Status code: #{status_code})")
|
61
|
+
return nil
|
62
|
+
end
|
63
|
+
|
64
|
+
UI.success("Successfully created label '#{params[:name]}' in #{repo_owner}/#{repo_name}")
|
65
|
+
|
66
|
+
# Set the shared values
|
67
|
+
Actions.lane_context[SharedValues::GITHUB_CREATE_LABEL_STATUS_CODE] = status_code
|
68
|
+
Actions.lane_context[SharedValues::GITHUB_CREATE_LABEL_RESPONSE] = response
|
69
|
+
Actions.lane_context[SharedValues::GITHUB_CREATE_LABEL_JSON] = response
|
70
|
+
|
71
|
+
return result
|
72
|
+
end
|
73
|
+
|
74
|
+
#####################################################
|
75
|
+
# @!group Documentation
|
76
|
+
#####################################################
|
77
|
+
|
78
|
+
def description
|
79
|
+
"Creates a label in a GitHub repository"
|
80
|
+
end
|
81
|
+
|
82
|
+
def details
|
83
|
+
[
|
84
|
+
"This action creates a new label in a GitHub repository with the specified name, color, and optional description.",
|
85
|
+
"It requires a valid GitHub API token with appropriate permissions.",
|
86
|
+
"Documentation: [https://docs.github.com/en/rest/issues/labels](https://docs.github.com/en/rest/issues/labels#create-a-label)"
|
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 with repo permissions",
|
95
|
+
optional: false,
|
96
|
+
type: String,
|
97
|
+
sensitive: true,
|
98
|
+
code_gen_sensitive: true,
|
99
|
+
default_value: ENV["GITHUB_API_TOKEN"],
|
100
|
+
verify_block: proc do |value|
|
101
|
+
UI.user_error!("No GitHub API token given, pass using `api_token: 'token'`") if value.to_s.empty?
|
102
|
+
end),
|
103
|
+
FastlaneCore::ConfigItem.new(key: :server_url,
|
104
|
+
env_name: "GITHUB_API_SERVER_URL",
|
105
|
+
description: "GitHub API server URL",
|
106
|
+
optional: true,
|
107
|
+
default_value: "https://api.github.com"),
|
108
|
+
FastlaneCore::ConfigItem.new(key: :repo_owner,
|
109
|
+
env_name: "GITHUB_API_REPO_OWNER",
|
110
|
+
description: "Repository owner (organization or username)",
|
111
|
+
optional: false,
|
112
|
+
type: String,
|
113
|
+
verify_block: proc do |value|
|
114
|
+
UI.user_error!("No repository owner provided, pass using `repo_owner: 'owner'`") if value.to_s.empty?
|
115
|
+
end),
|
116
|
+
FastlaneCore::ConfigItem.new(key: :repo_name,
|
117
|
+
env_name: "GITHUB_API_REPO_NAME",
|
118
|
+
description: "Repository name",
|
119
|
+
optional: false,
|
120
|
+
type: String,
|
121
|
+
verify_block: proc do |value|
|
122
|
+
UI.user_error!("No repository name provided, pass using `repo_name: 'name'`") if value.to_s.empty?
|
123
|
+
end),
|
124
|
+
FastlaneCore::ConfigItem.new(key: :name,
|
125
|
+
description: "The name of the label",
|
126
|
+
optional: false,
|
127
|
+
type: String,
|
128
|
+
verify_block: proc do |value|
|
129
|
+
UI.user_error!("No name provided, pass using `name: 'bug'`") if value.to_s.empty?
|
130
|
+
end),
|
131
|
+
FastlaneCore::ConfigItem.new(key: :color,
|
132
|
+
description: "The color of the label in hexadecimal format (with or without leading #)",
|
133
|
+
optional: false,
|
134
|
+
type: String,
|
135
|
+
verify_block: proc do |value|
|
136
|
+
value = value[1..-1] if value.start_with?('#')
|
137
|
+
UI.user_error!("Color must be a valid 6 character hex code") unless value.match?(/^[0-9A-Fa-f]{6}$/)
|
138
|
+
end),
|
139
|
+
FastlaneCore::ConfigItem.new(key: :description,
|
140
|
+
description: "A short description of the label",
|
141
|
+
optional: true,
|
142
|
+
type: String)
|
143
|
+
]
|
144
|
+
end
|
145
|
+
|
146
|
+
def output
|
147
|
+
[
|
148
|
+
['GITHUB_CREATE_LABEL_STATUS_CODE', 'The status code returned from the GitHub API'],
|
149
|
+
['GITHUB_CREATE_LABEL_RESPONSE', 'The full response from the GitHub API'],
|
150
|
+
['GITHUB_CREATE_LABEL_JSON', 'The JSON data returned from the GitHub API']
|
151
|
+
]
|
152
|
+
end
|
153
|
+
|
154
|
+
def return_value
|
155
|
+
"A hash including the HTTP status code (:status), the response body (:body), and the parsed JSON (:json)."
|
156
|
+
end
|
157
|
+
|
158
|
+
def authors
|
159
|
+
["crazymanish"]
|
160
|
+
end
|
161
|
+
|
162
|
+
def example_code
|
163
|
+
[
|
164
|
+
'github_create_label(
|
165
|
+
api_token: ENV["GITHUB_API_TOKEN"],
|
166
|
+
repo_owner: "fastlane",
|
167
|
+
repo_name: "fastlane",
|
168
|
+
name: "bug",
|
169
|
+
color: "d73a4a",
|
170
|
+
description: "Something isn\'t working"
|
171
|
+
)',
|
172
|
+
'# You can also access the response data
|
173
|
+
result = github_create_label(
|
174
|
+
api_token: ENV["GITHUB_API_TOKEN"],
|
175
|
+
repo_owner: "fastlane",
|
176
|
+
repo_name: "fastlane",
|
177
|
+
name: "enhancement",
|
178
|
+
color: "a2eeef"
|
179
|
+
)
|
180
|
+
UI.message("Created label with ID: #{result[:json]["id"]}")'
|
181
|
+
]
|
182
|
+
end
|
183
|
+
|
184
|
+
def category
|
185
|
+
:source_control
|
186
|
+
end
|
187
|
+
|
188
|
+
def is_supported?(platform)
|
189
|
+
true
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
@@ -0,0 +1,199 @@
|
|
1
|
+
require 'fastlane/action'
|
2
|
+
require_relative '../helper/github_api_helper'
|
3
|
+
|
4
|
+
module Fastlane
|
5
|
+
module Actions
|
6
|
+
module SharedValues
|
7
|
+
GITHUB_CREATE_MILESTONE_RESPONSE = :GITHUB_CREATE_MILESTONE_RESPONSE
|
8
|
+
GITHUB_CREATE_MILESTONE_JSON = :GITHUB_CREATE_MILESTONE_JSON
|
9
|
+
GITHUB_CREATE_MILESTONE_STATUS_CODE = :GITHUB_CREATE_MILESTONE_STATUS_CODE
|
10
|
+
end
|
11
|
+
|
12
|
+
class GithubCreateMilestoneAction < 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
|
+
server_url = params[:server_url]
|
19
|
+
|
20
|
+
# Validate parameters (additional validation beyond what's in ConfigItem)
|
21
|
+
UI.user_error!("No title provided for milestone, pass using `title: 'My Milestone'`") if params[:title].to_s.empty?
|
22
|
+
|
23
|
+
# Prepare request parameters
|
24
|
+
path = "/repos/#{repo_owner}/#{repo_name}/milestones"
|
25
|
+
|
26
|
+
# Build body parameters
|
27
|
+
body_params = {
|
28
|
+
title: params[:title]
|
29
|
+
}
|
30
|
+
|
31
|
+
# Add optional parameters if provided
|
32
|
+
body_params[:state] = params[:state] if params[:state]
|
33
|
+
body_params[:description] = params[:description] if params[:description]
|
34
|
+
body_params[:due_on] = params[:due_on] if params[:due_on]
|
35
|
+
|
36
|
+
# Make the request
|
37
|
+
UI.message("Creating milestone in #{repo_owner}/#{repo_name}: #{params[:title]}")
|
38
|
+
response = Helper::GithubApiHelper.github_api_request(
|
39
|
+
token: token,
|
40
|
+
path: path,
|
41
|
+
params: body_params,
|
42
|
+
method: :post,
|
43
|
+
server_url: server_url
|
44
|
+
)
|
45
|
+
|
46
|
+
status_code = response.key?('status') ? response['status'] : nil
|
47
|
+
result = {
|
48
|
+
status: status_code,
|
49
|
+
body: response,
|
50
|
+
json: response
|
51
|
+
}
|
52
|
+
|
53
|
+
if response.key?('error')
|
54
|
+
UI.error("GitHub responded with an error: #{response['error']}")
|
55
|
+
UI.user_error!("GitHub API error: #{response['error']}")
|
56
|
+
return nil
|
57
|
+
end
|
58
|
+
|
59
|
+
if response['message'] && status_code && status_code >= 400
|
60
|
+
UI.error("GitHub API error: #{response['message']}")
|
61
|
+
UI.user_error!("GitHub API error: #{response['message']} (Status code: #{status_code})")
|
62
|
+
return nil
|
63
|
+
end
|
64
|
+
|
65
|
+
milestone_number = response['number']
|
66
|
+
UI.success("Successfully created milestone ##{milestone_number} - #{response['title']} in #{repo_owner}/#{repo_name}")
|
67
|
+
|
68
|
+
# Set the shared values
|
69
|
+
Actions.lane_context[SharedValues::GITHUB_CREATE_MILESTONE_STATUS_CODE] = status_code
|
70
|
+
Actions.lane_context[SharedValues::GITHUB_CREATE_MILESTONE_RESPONSE] = response
|
71
|
+
Actions.lane_context[SharedValues::GITHUB_CREATE_MILESTONE_JSON] = response
|
72
|
+
|
73
|
+
return result
|
74
|
+
end
|
75
|
+
|
76
|
+
#####################################################
|
77
|
+
# @!group Documentation
|
78
|
+
#####################################################
|
79
|
+
|
80
|
+
def description
|
81
|
+
"Creates a new milestone in a GitHub repository"
|
82
|
+
end
|
83
|
+
|
84
|
+
def details
|
85
|
+
[
|
86
|
+
"This action creates a new milestone in a GitHub repository with the specified title and other optional parameters.",
|
87
|
+
"It requires a valid GitHub API token with appropriate permissions.",
|
88
|
+
"Documentation: [https://docs.github.com/en/rest/issues/milestones](https://docs.github.com/en/rest/issues/milestones#create-a-milestone)"
|
89
|
+
].join("\n")
|
90
|
+
end
|
91
|
+
|
92
|
+
def available_options
|
93
|
+
[
|
94
|
+
FastlaneCore::ConfigItem.new(key: :api_token,
|
95
|
+
env_name: "GITHUB_API_TOKEN",
|
96
|
+
description: "GitHub API token with repo permissions",
|
97
|
+
optional: false,
|
98
|
+
type: String,
|
99
|
+
sensitive: true,
|
100
|
+
code_gen_sensitive: true,
|
101
|
+
default_value: ENV["GITHUB_API_TOKEN"],
|
102
|
+
verify_block: proc do |value|
|
103
|
+
UI.user_error!("No GitHub API token given, pass using `api_token: 'token'`") if value.to_s.empty?
|
104
|
+
end),
|
105
|
+
FastlaneCore::ConfigItem.new(key: :server_url,
|
106
|
+
env_name: "GITHUB_API_SERVER_URL",
|
107
|
+
description: "GitHub API server URL",
|
108
|
+
optional: true,
|
109
|
+
default_value: "https://api.github.com"),
|
110
|
+
FastlaneCore::ConfigItem.new(key: :repo_owner,
|
111
|
+
env_name: "GITHUB_API_REPO_OWNER",
|
112
|
+
description: "Repository owner (organization or username)",
|
113
|
+
optional: false,
|
114
|
+
type: String,
|
115
|
+
verify_block: proc do |value|
|
116
|
+
UI.user_error!("No repository owner provided, pass using `repo_owner: 'owner'`") if value.to_s.empty?
|
117
|
+
end),
|
118
|
+
FastlaneCore::ConfigItem.new(key: :repo_name,
|
119
|
+
env_name: "GITHUB_API_REPO_NAME",
|
120
|
+
description: "Repository name",
|
121
|
+
optional: false,
|
122
|
+
type: String,
|
123
|
+
verify_block: proc do |value|
|
124
|
+
UI.user_error!("No repository name provided, pass using `repo_name: 'name'`") if value.to_s.empty?
|
125
|
+
end),
|
126
|
+
FastlaneCore::ConfigItem.new(key: :title,
|
127
|
+
description: "The title of the milestone",
|
128
|
+
optional: false,
|
129
|
+
type: String,
|
130
|
+
verify_block: proc do |value|
|
131
|
+
UI.user_error!("No title provided, pass using `title: 'v1.0'`") if value.to_s.empty?
|
132
|
+
end),
|
133
|
+
FastlaneCore::ConfigItem.new(key: :state,
|
134
|
+
description: "The state of the milestone (open or closed)",
|
135
|
+
optional: true,
|
136
|
+
default_value: "open",
|
137
|
+
type: String,
|
138
|
+
verify_block: proc do |value|
|
139
|
+
UI.user_error!("State must be 'open' or 'closed'") unless ['open', 'closed'].include?(value)
|
140
|
+
end),
|
141
|
+
FastlaneCore::ConfigItem.new(key: :description,
|
142
|
+
description: "A description of the milestone",
|
143
|
+
optional: true,
|
144
|
+
type: String),
|
145
|
+
FastlaneCore::ConfigItem.new(key: :due_on,
|
146
|
+
description: "The milestone due date in ISO 8601 format (YYYY-MM-DDTHH:MM:SSZ)",
|
147
|
+
optional: true,
|
148
|
+
type: String)
|
149
|
+
]
|
150
|
+
end
|
151
|
+
|
152
|
+
def output
|
153
|
+
[
|
154
|
+
['GITHUB_CREATE_MILESTONE_STATUS_CODE', 'The status code returned from the GitHub API'],
|
155
|
+
['GITHUB_CREATE_MILESTONE_RESPONSE', 'The full response from the GitHub API'],
|
156
|
+
['GITHUB_CREATE_MILESTONE_JSON', 'The JSON data returned from the GitHub API']
|
157
|
+
]
|
158
|
+
end
|
159
|
+
|
160
|
+
def return_value
|
161
|
+
"A hash including the HTTP status code (:status), the response body (:body), and the parsed JSON (:json)."
|
162
|
+
end
|
163
|
+
|
164
|
+
def authors
|
165
|
+
["crazymanish"]
|
166
|
+
end
|
167
|
+
|
168
|
+
def example_code
|
169
|
+
[
|
170
|
+
'github_create_milestone(
|
171
|
+
api_token: ENV["GITHUB_API_TOKEN"],
|
172
|
+
repo_owner: "fastlane",
|
173
|
+
repo_name: "fastlane",
|
174
|
+
title: "v1.0",
|
175
|
+
description: "First stable release",
|
176
|
+
due_on: "2023-12-31T23:59:59Z"
|
177
|
+
)',
|
178
|
+
'# You can also access the response data
|
179
|
+
result = github_create_milestone(
|
180
|
+
api_token: ENV["GITHUB_API_TOKEN"],
|
181
|
+
repo_owner: "fastlane",
|
182
|
+
repo_name: "fastlane",
|
183
|
+
title: "v2.0"
|
184
|
+
)
|
185
|
+
UI.message("Created milestone number: #{result[:json]["number"]}")'
|
186
|
+
]
|
187
|
+
end
|
188
|
+
|
189
|
+
def category
|
190
|
+
:source_control
|
191
|
+
end
|
192
|
+
|
193
|
+
def is_supported?(platform)
|
194
|
+
true
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|