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.
Files changed (79) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/README.md +824 -0
  4. data/lib/fastlane/plugin/github_api/actions/github_add_assignees_action.rb +191 -0
  5. data/lib/fastlane/plugin/github_api/actions/github_add_issue_comment_action.rb +184 -0
  6. data/lib/fastlane/plugin/github_api/actions/github_add_labels_action.rb +191 -0
  7. data/lib/fastlane/plugin/github_api/actions/github_api_action.rb +47 -0
  8. data/lib/fastlane/plugin/github_api/actions/github_check_pull_merged_action.rb +152 -0
  9. data/lib/fastlane/plugin/github_api/actions/github_create_commit_comment_reaction_action.rb +168 -0
  10. data/lib/fastlane/plugin/github_api/actions/github_create_issue_action.rb +199 -0
  11. data/lib/fastlane/plugin/github_api/actions/github_create_issue_comment_reaction_action.rb +168 -0
  12. data/lib/fastlane/plugin/github_api/actions/github_create_issue_reaction_action.rb +168 -0
  13. data/lib/fastlane/plugin/github_api/actions/github_create_label_action.rb +194 -0
  14. data/lib/fastlane/plugin/github_api/actions/github_create_milestone_action.rb +199 -0
  15. data/lib/fastlane/plugin/github_api/actions/github_create_pull_action.rb +202 -0
  16. data/lib/fastlane/plugin/github_api/actions/github_create_pull_comment_action.rb +229 -0
  17. data/lib/fastlane/plugin/github_api/actions/github_create_pull_comment_reaction_action.rb +168 -0
  18. data/lib/fastlane/plugin/github_api/actions/github_create_pull_review_action.rb +224 -0
  19. data/lib/fastlane/plugin/github_api/actions/github_create_repository_action.rb +230 -0
  20. data/lib/fastlane/plugin/github_api/actions/github_delete_commit_comment_reaction_action.rb +152 -0
  21. data/lib/fastlane/plugin/github_api/actions/github_delete_issue_comment_action.rb +153 -0
  22. data/lib/fastlane/plugin/github_api/actions/github_delete_issue_comment_reaction_action.rb +152 -0
  23. data/lib/fastlane/plugin/github_api/actions/github_delete_issue_reaction_action.rb +152 -0
  24. data/lib/fastlane/plugin/github_api/actions/github_delete_label_action.rb +164 -0
  25. data/lib/fastlane/plugin/github_api/actions/github_delete_milestone_action.rb +159 -0
  26. data/lib/fastlane/plugin/github_api/actions/github_delete_pull_comment_action.rb +144 -0
  27. data/lib/fastlane/plugin/github_api/actions/github_delete_pull_comment_reaction_action.rb +152 -0
  28. data/lib/fastlane/plugin/github_api/actions/github_delete_repository_action.rb +166 -0
  29. data/lib/fastlane/plugin/github_api/actions/github_dismiss_pull_review_action.rb +168 -0
  30. data/lib/fastlane/plugin/github_api/actions/github_get_issue_action.rb +166 -0
  31. data/lib/fastlane/plugin/github_api/actions/github_get_issue_comment_action.rb +174 -0
  32. data/lib/fastlane/plugin/github_api/actions/github_get_issue_event_action.rb +169 -0
  33. data/lib/fastlane/plugin/github_api/actions/github_get_issue_timeline_action.rb +199 -0
  34. data/lib/fastlane/plugin/github_api/actions/github_get_milestone_action.rb +167 -0
  35. data/lib/fastlane/plugin/github_api/actions/github_get_pull_action.rb +150 -0
  36. data/lib/fastlane/plugin/github_api/actions/github_get_pull_comment_action.rb +147 -0
  37. data/lib/fastlane/plugin/github_api/actions/github_get_pull_review_action.rb +137 -0
  38. data/lib/fastlane/plugin/github_api/actions/github_get_pull_review_comments_action.rb +181 -0
  39. data/lib/fastlane/plugin/github_api/actions/github_list_all_pull_comments_action.rb +186 -0
  40. data/lib/fastlane/plugin/github_api/actions/github_list_commit_comment_reactions_action.rb +183 -0
  41. data/lib/fastlane/plugin/github_api/actions/github_list_issue_comment_reactions_action.rb +183 -0
  42. data/lib/fastlane/plugin/github_api/actions/github_list_issue_comments_action.rb +197 -0
  43. data/lib/fastlane/plugin/github_api/actions/github_list_issue_events_action.rb +191 -0
  44. data/lib/fastlane/plugin/github_api/actions/github_list_issue_labels_action.rb +192 -0
  45. data/lib/fastlane/plugin/github_api/actions/github_list_issue_reactions_action.rb +183 -0
  46. data/lib/fastlane/plugin/github_api/actions/github_list_issues_action.rb +236 -0
  47. data/lib/fastlane/plugin/github_api/actions/github_list_milestones_action.rb +205 -0
  48. data/lib/fastlane/plugin/github_api/actions/github_list_pull_comment_reactions_action.rb +183 -0
  49. data/lib/fastlane/plugin/github_api/actions/github_list_pull_comments_action.rb +203 -0
  50. data/lib/fastlane/plugin/github_api/actions/github_list_pull_commits_action.rb +175 -0
  51. data/lib/fastlane/plugin/github_api/actions/github_list_pull_files_action.rb +174 -0
  52. data/lib/fastlane/plugin/github_api/actions/github_list_pull_reviewers_action.rb +163 -0
  53. data/lib/fastlane/plugin/github_api/actions/github_list_pull_reviews_action.rb +175 -0
  54. data/lib/fastlane/plugin/github_api/actions/github_list_pulls_action.rb +206 -0
  55. data/lib/fastlane/plugin/github_api/actions/github_list_repo_issue_events_action.rb +185 -0
  56. data/lib/fastlane/plugin/github_api/actions/github_list_repo_labels_action.rb +184 -0
  57. data/lib/fastlane/plugin/github_api/actions/github_lock_issue_action.rb +180 -0
  58. data/lib/fastlane/plugin/github_api/actions/github_merge_pull_action.rb +191 -0
  59. data/lib/fastlane/plugin/github_api/actions/github_remove_all_labels_action.rb +160 -0
  60. data/lib/fastlane/plugin/github_api/actions/github_remove_assignees_action.rb +195 -0
  61. data/lib/fastlane/plugin/github_api/actions/github_remove_label_action.rb +172 -0
  62. data/lib/fastlane/plugin/github_api/actions/github_remove_pull_reviewers_action.rb +169 -0
  63. data/lib/fastlane/plugin/github_api/actions/github_request_pull_review_action.rb +169 -0
  64. data/lib/fastlane/plugin/github_api/actions/github_set_labels_action.rb +191 -0
  65. data/lib/fastlane/plugin/github_api/actions/github_submit_pull_comment_action.rb +185 -0
  66. data/lib/fastlane/plugin/github_api/actions/github_submit_pull_review_action.rb +187 -0
  67. data/lib/fastlane/plugin/github_api/actions/github_unlock_issue_action.rb +157 -0
  68. data/lib/fastlane/plugin/github_api/actions/github_update_issue_action.rb +202 -0
  69. data/lib/fastlane/plugin/github_api/actions/github_update_issue_comment_action.rb +172 -0
  70. data/lib/fastlane/plugin/github_api/actions/github_update_label_action.rb +204 -0
  71. data/lib/fastlane/plugin/github_api/actions/github_update_milestone_action.rb +198 -0
  72. data/lib/fastlane/plugin/github_api/actions/github_update_pull_action.rb +191 -0
  73. data/lib/fastlane/plugin/github_api/actions/github_update_pull_branch_action.rb +158 -0
  74. data/lib/fastlane/plugin/github_api/actions/github_update_pull_comment_action.rb +156 -0
  75. data/lib/fastlane/plugin/github_api/actions/github_update_pull_review_action.rb +151 -0
  76. data/lib/fastlane/plugin/github_api/helper/github_api_helper.rb +123 -0
  77. data/lib/fastlane/plugin/github_api/version.rb +5 -0
  78. data/lib/fastlane/plugin/github_api.rb +16 -0
  79. metadata +120 -0
@@ -0,0 +1,159 @@
1
+ require 'fastlane/action'
2
+ require_relative '../helper/github_api_helper'
3
+
4
+ module Fastlane
5
+ module Actions
6
+ module SharedValues
7
+ GITHUB_DELETE_MILESTONE_RESPONSE = :GITHUB_DELETE_MILESTONE_RESPONSE
8
+ GITHUB_DELETE_MILESTONE_JSON = :GITHUB_DELETE_MILESTONE_JSON
9
+ GITHUB_DELETE_MILESTONE_STATUS_CODE = :GITHUB_DELETE_MILESTONE_STATUS_CODE
10
+ end
11
+
12
+ class GithubDeleteMilestoneAction < 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
+ milestone_number = params[:milestone_number]
19
+ server_url = params[:server_url]
20
+
21
+ # Validate parameters (additional validation beyond what's in ConfigItem)
22
+ UI.user_error!("No GitHub milestone number given, pass using `milestone_number: 42`") unless milestone_number.to_s.length > 0
23
+
24
+ # Prepare request parameters
25
+ path = "/repos/#{repo_owner}/#{repo_name}/milestones/#{milestone_number}"
26
+
27
+ # Make the request
28
+ UI.message("Deleting milestone ##{milestone_number} from #{repo_owner}/#{repo_name}")
29
+ response = Helper::GithubApiHelper.github_api_request(
30
+ token: token,
31
+ path: path,
32
+ method: :delete,
33
+ server_url: server_url
34
+ )
35
+
36
+ status_code = response.key?('status') ? response['status'] : nil
37
+ result = {
38
+ status: status_code,
39
+ body: response,
40
+ json: response
41
+ }
42
+
43
+ if response.key?('error')
44
+ UI.error("GitHub responded with an error: #{response['error']}")
45
+ UI.user_error!("GitHub API error: #{response['error']}")
46
+ return nil
47
+ end
48
+
49
+ if response.is_a?(Hash) && response['message'] && status_code && status_code >= 400
50
+ UI.error("GitHub API error: #{response['message']}")
51
+ UI.user_error!("GitHub API error: #{response['message']} (Status code: #{status_code})")
52
+ return nil
53
+ end
54
+
55
+ UI.success("Successfully deleted milestone ##{milestone_number} from #{repo_owner}/#{repo_name}")
56
+
57
+ # Set the shared values
58
+ Actions.lane_context[SharedValues::GITHUB_DELETE_MILESTONE_STATUS_CODE] = status_code
59
+ Actions.lane_context[SharedValues::GITHUB_DELETE_MILESTONE_RESPONSE] = response
60
+ Actions.lane_context[SharedValues::GITHUB_DELETE_MILESTONE_JSON] = response
61
+
62
+ return result
63
+ end
64
+
65
+ #####################################################
66
+ # @!group Documentation
67
+ #####################################################
68
+
69
+ def description
70
+ "Deletes a milestone from a GitHub repository"
71
+ end
72
+
73
+ def details
74
+ [
75
+ "This action deletes a milestone from a GitHub repository by its milestone number.",
76
+ "It requires a valid GitHub API token with appropriate permissions.",
77
+ "Documentation: [https://docs.github.com/en/rest/issues/milestones](https://docs.github.com/en/rest/issues/milestones#delete-a-milestone)"
78
+ ].join("\n")
79
+ end
80
+
81
+ def available_options
82
+ [
83
+ FastlaneCore::ConfigItem.new(key: :api_token,
84
+ env_name: "GITHUB_API_TOKEN",
85
+ description: "GitHub API token with repo permissions",
86
+ optional: false,
87
+ type: String,
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: "Repository owner (organization or username)",
102
+ optional: false,
103
+ type: String,
104
+ verify_block: proc do |value|
105
+ UI.user_error!("No repository owner provided, pass using `repo_owner: 'owner'`") if value.to_s.empty?
106
+ end),
107
+ FastlaneCore::ConfigItem.new(key: :repo_name,
108
+ env_name: "GITHUB_API_REPO_NAME",
109
+ description: "Repository name",
110
+ optional: false,
111
+ type: String,
112
+ verify_block: proc do |value|
113
+ UI.user_error!("No repository name provided, pass using `repo_name: 'name'`") if value.to_s.empty?
114
+ end),
115
+ FastlaneCore::ConfigItem.new(key: :milestone_number,
116
+ description: "The milestone number to delete",
117
+ optional: false,
118
+ type: Integer)
119
+ ]
120
+ end
121
+
122
+ def output
123
+ [
124
+ ['GITHUB_DELETE_MILESTONE_STATUS_CODE', 'The status code returned from the GitHub API'],
125
+ ['GITHUB_DELETE_MILESTONE_RESPONSE', 'The full response from the GitHub API'],
126
+ ['GITHUB_DELETE_MILESTONE_JSON', 'The JSON data returned from the GitHub API']
127
+ ]
128
+ end
129
+
130
+ def return_value
131
+ "A hash including the HTTP status code (:status), the response body (:body), and the parsed JSON (:json)."
132
+ end
133
+
134
+ def authors
135
+ ["crazymanish"]
136
+ end
137
+
138
+ def example_code
139
+ [
140
+ 'github_delete_milestone(
141
+ api_token: ENV["GITHUB_API_TOKEN"],
142
+ repo_owner: "fastlane",
143
+ repo_name: "fastlane",
144
+ milestone_number: 42
145
+ )'
146
+ ]
147
+ end
148
+
149
+ def category
150
+ :source_control
151
+ end
152
+
153
+ def is_supported?(platform)
154
+ true
155
+ end
156
+ end
157
+ end
158
+ end
159
+ end
@@ -0,0 +1,144 @@
1
+ require 'fastlane/action'
2
+ require_relative '../helper/github_api_helper'
3
+
4
+ module Fastlane
5
+ module Actions
6
+ module SharedValues
7
+ GITHUB_DELETE_PULL_COMMENT_STATUS_CODE = :GITHUB_DELETE_PULL_COMMENT_STATUS_CODE
8
+ GITHUB_DELETE_PULL_COMMENT_RESPONSE = :GITHUB_DELETE_PULL_COMMENT_RESPONSE
9
+ end
10
+
11
+ class GithubDeletePullCommentAction < Action
12
+ class << self
13
+ def run(params)
14
+ require 'json'
15
+
16
+ # Prepare API call parameters
17
+ server_url = params[:server_url]
18
+ api_token = params[:api_token]
19
+ repo_owner = params[:repo_owner]
20
+ repo_name = params[:repo_name]
21
+ comment_id = params[:comment_id]
22
+
23
+ # Build the path
24
+ path = "/repos/#{repo_owner}/#{repo_name}/pulls/comments/#{comment_id}"
25
+
26
+ UI.message("Deleting pull request comment #{comment_id} from #{repo_owner}/#{repo_name}")
27
+ response = Helper::GithubApiHelper.github_api_request(
28
+ token: api_token,
29
+ path: path,
30
+ method: :delete,
31
+ server_url: server_url
32
+ )
33
+
34
+ status_code = response[:status]
35
+ result = {
36
+ status: status_code,
37
+ body: response[:body]
38
+ }
39
+
40
+ if status_code.between?(200, 299) || status_code == 204
41
+ UI.success("Successfully deleted pull request comment #{comment_id}")
42
+ else
43
+ UI.error("Error deleting pull request comment: #{status_code}")
44
+ UI.error(response[:body])
45
+ UI.user_error!("GitHub API returned #{status_code}: #{response[:body]}")
46
+ return nil
47
+ end
48
+
49
+ # Store the results in shared values
50
+ Actions.lane_context[SharedValues::GITHUB_DELETE_PULL_COMMENT_STATUS_CODE] = status_code
51
+ Actions.lane_context[SharedValues::GITHUB_DELETE_PULL_COMMENT_RESPONSE] = response[:body]
52
+
53
+ return result
54
+ end
55
+
56
+ #####################################################
57
+ # @!group Documentation
58
+ #####################################################
59
+
60
+ def description
61
+ "Deletes a pull request comment"
62
+ end
63
+
64
+ def details
65
+ [
66
+ "Deletes a review comment from a pull request.",
67
+ "You must provide your GitHub Personal token (get one from https://github.com/settings/tokens/new).",
68
+ "API Documentation: https://docs.github.com/en/rest/pulls/comments#delete-a-review-comment-for-a-pull-request"
69
+ ].join("\n")
70
+ end
71
+
72
+ def available_options
73
+ [
74
+ FastlaneCore::ConfigItem.new(key: :api_token,
75
+ env_name: "GITHUB_API_TOKEN",
76
+ description: "GitHub API token",
77
+ optional: false,
78
+ sensitive: true,
79
+ code_gen_sensitive: true,
80
+ default_value: ENV["GITHUB_API_TOKEN"],
81
+ verify_block: proc do |value|
82
+ UI.user_error!("No GitHub API token given, pass using `api_token: 'token'`") if value.to_s.empty?
83
+ end),
84
+ FastlaneCore::ConfigItem.new(key: :server_url,
85
+ env_name: "GITHUB_API_SERVER_URL",
86
+ description: "GitHub API server URL",
87
+ optional: true,
88
+ default_value: "https://api.github.com"),
89
+ FastlaneCore::ConfigItem.new(key: :repo_owner,
90
+ env_name: "GITHUB_API_REPO_OWNER",
91
+ description: "Owner of the repository",
92
+ optional: false),
93
+ FastlaneCore::ConfigItem.new(key: :repo_name,
94
+ env_name: "GITHUB_API_REPO_NAME",
95
+ description: "Name of the repository",
96
+ optional: false),
97
+ FastlaneCore::ConfigItem.new(key: :comment_id,
98
+ env_name: "GITHUB_API_PR_COMMENT_ID",
99
+ description: "The ID of the comment to delete",
100
+ optional: false,
101
+ type: Integer)
102
+ ]
103
+ end
104
+
105
+ def output
106
+ [
107
+ ['GITHUB_DELETE_PULL_COMMENT_STATUS_CODE', 'The status code returned by the GitHub API'],
108
+ ['GITHUB_DELETE_PULL_COMMENT_RESPONSE', 'The full response body returned by the GitHub API']
109
+ ]
110
+ end
111
+
112
+ def return_value
113
+ "Returns a hash containing the status code and response body from the GitHub API."
114
+ end
115
+
116
+ def authors
117
+ ["crazymanish"]
118
+ end
119
+
120
+ def is_supported?(platform)
121
+ true
122
+ end
123
+
124
+ def example_code
125
+ [
126
+ 'github_delete_pull_comment(
127
+ repo_owner: "octocat",
128
+ repo_name: "Hello-World",
129
+ comment_id: 12345
130
+ )',
131
+ 'result = github_delete_pull_comment(
132
+ repo_owner: "octocat",
133
+ repo_name: "Hello-World",
134
+ comment_id: 12345
135
+ )
136
+ if result[:status] == 204
137
+ UI.message("Comment successfully deleted")
138
+ end'
139
+ ]
140
+ end
141
+ end
142
+ end
143
+ end
144
+ end
@@ -0,0 +1,152 @@
1
+ require 'fastlane/action'
2
+ require_relative '../helper/github_api_helper'
3
+
4
+ module Fastlane
5
+ module Actions
6
+ module SharedValues
7
+ GITHUB_DELETE_PULL_COMMENT_REACTION_STATUS_CODE = :GITHUB_DELETE_PULL_COMMENT_REACTION_STATUS_CODE
8
+ GITHUB_DELETE_PULL_COMMENT_REACTION_RESPONSE = :GITHUB_DELETE_PULL_COMMENT_REACTION_RESPONSE
9
+ end
10
+
11
+ class GithubDeletePullCommentReactionAction < Action
12
+ class << self
13
+ def run(params)
14
+ # Prepare API call parameters
15
+ server_url = params[:server_url]
16
+ api_token = params[:api_token]
17
+ repo_owner = params[:repo_owner]
18
+ repo_name = params[:repo_name]
19
+ comment_id = params[:comment_id]
20
+ reaction_id = params[:reaction_id]
21
+
22
+ # Build the path
23
+ path = "/repos/#{repo_owner}/#{repo_name}/pulls/comments/#{comment_id}/reactions/#{reaction_id}"
24
+
25
+ UI.message("Deleting reaction ##{reaction_id} for pull request review comment ##{comment_id} in #{repo_owner}/#{repo_name}")
26
+ response = Helper::GithubApiHelper.github_api_request(
27
+ token: api_token,
28
+ path: path,
29
+ method: :delete,
30
+ server_url: server_url,
31
+ headers: { 'Accept' => 'application/vnd.github.squirrel-girl-preview+json' }
32
+ )
33
+
34
+ status_code = response[:status]
35
+ result = {
36
+ status: status_code,
37
+ body: response[:body]
38
+ }
39
+
40
+ if status_code == 204
41
+ UI.success("Successfully deleted reaction ##{reaction_id} for pull request review comment ##{comment_id}")
42
+ else
43
+ UI.error("Error deleting reaction: #{status_code}")
44
+ UI.error(response[:body])
45
+ UI.user_error!("GitHub API returned #{status_code}: #{response[:body]}")
46
+ return nil
47
+ end
48
+
49
+ # Store the results in shared values
50
+ Actions.lane_context[SharedValues::GITHUB_DELETE_PULL_COMMENT_REACTION_STATUS_CODE] = status_code
51
+ Actions.lane_context[SharedValues::GITHUB_DELETE_PULL_COMMENT_REACTION_RESPONSE] = response[:body]
52
+
53
+ return result
54
+ end
55
+
56
+ #####################################################
57
+ # @!group Documentation
58
+ #####################################################
59
+
60
+ def description
61
+ "Delete a reaction from a pull request review comment"
62
+ end
63
+
64
+ def details
65
+ [
66
+ "Deletes a reaction from a pull request review comment.",
67
+ "You must provide your GitHub Personal token (get one from https://github.com/settings/tokens/new).",
68
+ "API Documentation: https://docs.github.com/en/rest/reactions/reactions#delete-a-pull-request-comment-reaction"
69
+ ].join("\n")
70
+ end
71
+
72
+ def available_options
73
+ [
74
+ FastlaneCore::ConfigItem.new(key: :api_token,
75
+ env_name: "GITHUB_API_TOKEN",
76
+ description: "GitHub API token",
77
+ optional: false,
78
+ sensitive: true,
79
+ code_gen_sensitive: true,
80
+ default_value: ENV["GITHUB_API_TOKEN"],
81
+ verify_block: proc do |value|
82
+ UI.user_error!("No GitHub API token given, pass using `api_token: 'token'`") if value.to_s.empty?
83
+ end),
84
+ FastlaneCore::ConfigItem.new(key: :server_url,
85
+ env_name: "GITHUB_API_SERVER_URL",
86
+ description: "GitHub API server URL",
87
+ optional: true,
88
+ default_value: "https://api.github.com"),
89
+ FastlaneCore::ConfigItem.new(key: :repo_owner,
90
+ env_name: "GITHUB_API_REPO_OWNER",
91
+ description: "Owner of the repository",
92
+ optional: false),
93
+ FastlaneCore::ConfigItem.new(key: :repo_name,
94
+ env_name: "GITHUB_API_REPO_NAME",
95
+ description: "Name of the repository",
96
+ optional: false),
97
+ FastlaneCore::ConfigItem.new(key: :comment_id,
98
+ env_name: "GITHUB_API_COMMENT_ID",
99
+ description: "The ID of the pull request review comment",
100
+ optional: false,
101
+ type: Integer),
102
+ FastlaneCore::ConfigItem.new(key: :reaction_id,
103
+ env_name: "GITHUB_API_REACTION_ID",
104
+ description: "The ID of the reaction to delete",
105
+ optional: false,
106
+ type: Integer)
107
+ ]
108
+ end
109
+
110
+ def output
111
+ [
112
+ ['GITHUB_DELETE_PULL_COMMENT_REACTION_STATUS_CODE', 'The status code returned by the GitHub API'],
113
+ ['GITHUB_DELETE_PULL_COMMENT_REACTION_RESPONSE', 'The full response body returned by the GitHub API']
114
+ ]
115
+ end
116
+
117
+ def return_value
118
+ "Returns a hash containing the status code and response body from the GitHub API."
119
+ end
120
+
121
+ def authors
122
+ ["crazymanish"]
123
+ end
124
+
125
+ def is_supported?(platform)
126
+ true
127
+ end
128
+
129
+ def example_code
130
+ [
131
+ 'github_delete_pull_comment_reaction(
132
+ repo_owner: "octocat",
133
+ repo_name: "Hello-World",
134
+ comment_id: 123,
135
+ reaction_id: 456
136
+ )',
137
+ 'result = github_delete_pull_comment_reaction(
138
+ repo_owner: "octocat",
139
+ repo_name: "Hello-World",
140
+ comment_id: 123,
141
+ reaction_id: 456
142
+ )
143
+
144
+ if result[:status] == 204
145
+ puts "Reaction deleted successfully!"
146
+ end'
147
+ ]
148
+ end
149
+ end
150
+ end
151
+ end
152
+ end
@@ -0,0 +1,166 @@
1
+ require 'fastlane/action'
2
+ require_relative '../helper/github_api_helper'
3
+
4
+ module Fastlane
5
+ module Actions
6
+ module SharedValues
7
+ GITHUB_DELETE_REPOSITORY_STATUS_CODE = :GITHUB_DELETE_REPOSITORY_STATUS_CODE
8
+ GITHUB_DELETE_REPOSITORY_RESPONSE = :GITHUB_DELETE_REPOSITORY_RESPONSE
9
+ GITHUB_DELETE_REPOSITORY_JSON = :GITHUB_DELETE_REPOSITORY_JSON
10
+ end
11
+
12
+ class GithubDeleteRepositoryAction < 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
+
23
+ # Validate parameters
24
+ UI.user_error!("No repository owner provided, pass using `repo_owner: 'owner'`") if repo_owner.to_s.empty?
25
+ UI.user_error!("No repository name provided, pass using `repo_name: 'name'`") if repo_name.to_s.empty?
26
+
27
+ # Build the path
28
+ path = "/repos/#{repo_owner}/#{repo_name}"
29
+
30
+ # Add confirmation
31
+ if !params[:confirm]
32
+ UI.important("⚠️ Are you sure you want to delete the repository '#{repo_owner}/#{repo_name}'?")
33
+ UI.important("This action is irreversible and will delete all repository data!")
34
+ UI.important("To confirm, pass `confirm: true` to this action.")
35
+ UI.user_error!("Repository deletion was not confirmed")
36
+ return nil
37
+ end
38
+
39
+ UI.message("Deleting repository: #{repo_owner}/#{repo_name}")
40
+ response = Helper::GithubApiHelper.github_api_request(
41
+ token: api_token,
42
+ path: path,
43
+ method: :delete,
44
+ server_url: server_url
45
+ )
46
+
47
+ status_code = response[:status]
48
+ result = {
49
+ status: status_code,
50
+ body: response[:body],
51
+ json: response[:json]
52
+ }
53
+
54
+ if status_code.between?(200, 299) || status_code == 204
55
+ UI.success("Successfully deleted repository: #{repo_owner}/#{repo_name}")
56
+ else
57
+ UI.error("Error deleting repository: #{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_DELETE_REPOSITORY_STATUS_CODE] = status_code
65
+ Actions.lane_context[SharedValues::GITHUB_DELETE_REPOSITORY_RESPONSE] = response[:body]
66
+ Actions.lane_context[SharedValues::GITHUB_DELETE_REPOSITORY_JSON] = response[:json]
67
+
68
+ return result
69
+ end
70
+
71
+ #####################################################
72
+ # @!group Documentation
73
+ #####################################################
74
+
75
+ def description
76
+ "Deletes a GitHub repository"
77
+ end
78
+
79
+ def details
80
+ [
81
+ "Deletes a repository on GitHub.",
82
+ "WARNING: This action is irreversible and will delete all repository data, issues, pull requests, and releases!",
83
+ "You must provide your GitHub Personal token with delete repository permissions (get one from https://github.com/settings/tokens/new).",
84
+ "API Documentation: https://docs.github.com/en/rest/repos/repos#delete-a-repository"
85
+ ].join("\n")
86
+ end
87
+
88
+ def available_options
89
+ [
90
+ FastlaneCore::ConfigItem.new(key: :api_token,
91
+ env_name: "GITHUB_API_TOKEN",
92
+ description: "GitHub API token with delete repo permissions",
93
+ optional: false,
94
+ sensitive: true,
95
+ code_gen_sensitive: true,
96
+ default_value: ENV["GITHUB_API_TOKEN"],
97
+ verify_block: proc do |value|
98
+ UI.user_error!("No GitHub API token given, pass using `api_token: 'token'`") if value.to_s.empty?
99
+ end),
100
+ FastlaneCore::ConfigItem.new(key: :server_url,
101
+ env_name: "GITHUB_API_SERVER_URL",
102
+ description: "GitHub API server URL",
103
+ optional: true,
104
+ default_value: "https://api.github.com"),
105
+ FastlaneCore::ConfigItem.new(key: :repo_owner,
106
+ env_name: "GITHUB_API_REPO_OWNER",
107
+ description: "Repository owner (organization or username)",
108
+ optional: false,
109
+ type: String,
110
+ verify_block: proc do |value|
111
+ UI.user_error!("No repository owner provided, pass using `repo_owner: 'owner'`") if value.to_s.empty?
112
+ end),
113
+ FastlaneCore::ConfigItem.new(key: :repo_name,
114
+ env_name: "GITHUB_API_REPO_NAME",
115
+ description: "Repository name",
116
+ optional: false,
117
+ type: String,
118
+ verify_block: proc do |value|
119
+ UI.user_error!("No repository name provided, pass using `repo_name: 'name'`") if value.to_s.empty?
120
+ end),
121
+ FastlaneCore::ConfigItem.new(key: :confirm,
122
+ description: "Confirm repository deletion. Must be set to true to delete the repository",
123
+ optional: false,
124
+ is_string: false,
125
+ default_value: false)
126
+ ]
127
+ end
128
+
129
+ def output
130
+ [
131
+ ['GITHUB_DELETE_REPOSITORY_STATUS_CODE', 'The status code returned from the GitHub API'],
132
+ ['GITHUB_DELETE_REPOSITORY_RESPONSE', 'The full response body from the GitHub API'],
133
+ ['GITHUB_DELETE_REPOSITORY_JSON', 'The parsed JSON returned from the GitHub API']
134
+ ]
135
+ end
136
+
137
+ def return_value
138
+ "A hash including the HTTP status code (:status), the response body (:body), and the parsed JSON (:json)."
139
+ end
140
+
141
+ def authors
142
+ ["crazymanish"]
143
+ end
144
+
145
+ def example_code
146
+ [
147
+ 'github_delete_repository(
148
+ api_token: ENV["GITHUB_API_TOKEN"],
149
+ repo_owner: "username",
150
+ repo_name: "repo-to-delete",
151
+ confirm: true
152
+ )'
153
+ ]
154
+ end
155
+
156
+ def category
157
+ :source_control
158
+ end
159
+
160
+ def is_supported?(platform)
161
+ true
162
+ end
163
+ end
164
+ end
165
+ end
166
+ end