fastlane-plugin-circle_ci 0.2.0 → 0.3.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 (69) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +272 -3
  3. data/lib/fastlane/plugin/circle_ci/actions/circleci_add_context_env_var.rb +117 -0
  4. data/lib/fastlane/plugin/circle_ci/actions/circleci_add_project_collaborator.rb +109 -0
  5. data/lib/fastlane/plugin/circle_ci/actions/circleci_approve_job.rb +95 -0
  6. data/lib/fastlane/plugin/circle_ci/actions/circleci_cancel_job.rb +96 -0
  7. data/lib/fastlane/plugin/circle_ci/actions/circleci_cancel_workflow.rb +85 -0
  8. data/lib/fastlane/plugin/circle_ci/actions/circleci_continue_pipeline.rb +104 -0
  9. data/lib/fastlane/plugin/circle_ci/actions/circleci_create_checkout_key.rb +110 -0
  10. data/lib/fastlane/plugin/circle_ci/actions/circleci_create_pipeline_definition.rb +126 -0
  11. data/lib/fastlane/plugin/circle_ci/actions/circleci_create_pipeline_definition_trigger.rb +133 -0
  12. data/lib/fastlane/plugin/circle_ci/actions/circleci_create_pipeline_schedule.rb +160 -0
  13. data/lib/fastlane/plugin/circle_ci/actions/circleci_create_project.rb +105 -0
  14. data/lib/fastlane/plugin/circle_ci/actions/circleci_create_webhook.rb +155 -0
  15. data/lib/fastlane/plugin/circle_ci/actions/circleci_delete_checkout_key.rb +93 -0
  16. data/lib/fastlane/plugin/circle_ci/actions/circleci_delete_context_env_var.rb +110 -0
  17. data/lib/fastlane/plugin/circle_ci/actions/circleci_delete_env_var.rb +86 -0
  18. data/lib/fastlane/plugin/circle_ci/actions/circleci_delete_pipeline_definition.rb +91 -0
  19. data/lib/fastlane/plugin/circle_ci/actions/circleci_delete_pipeline_schedule.rb +95 -0
  20. data/lib/fastlane/plugin/circle_ci/actions/circleci_delete_trigger.rb +92 -0
  21. data/lib/fastlane/plugin/circle_ci/actions/circleci_delete_webhook.rb +86 -0
  22. data/lib/fastlane/plugin/circle_ci/actions/circleci_download_artifact.rb +119 -0
  23. data/lib/fastlane/plugin/circle_ci/actions/circleci_download_workflow_artifacts.rb +400 -0
  24. data/lib/fastlane/plugin/circle_ci/actions/circleci_get_checkout_key.rb +101 -0
  25. data/lib/fastlane/plugin/circle_ci/actions/circleci_get_checkout_keys.rb +96 -0
  26. data/lib/fastlane/plugin/circle_ci/actions/circleci_get_context_env_vars.rb +114 -0
  27. data/lib/fastlane/plugin/circle_ci/actions/circleci_get_env_vars.rb +95 -0
  28. data/lib/fastlane/plugin/circle_ci/actions/circleci_get_flaky_tests.rb +99 -0
  29. data/lib/fastlane/plugin/circle_ci/actions/circleci_get_job_artifacts.rb +111 -0
  30. data/lib/fastlane/plugin/circle_ci/actions/circleci_get_job_details.rb +110 -0
  31. data/lib/fastlane/plugin/circle_ci/actions/circleci_get_job_tests.rb +111 -0
  32. data/lib/fastlane/plugin/circle_ci/actions/circleci_get_job_timeseries.rb +131 -0
  33. data/lib/fastlane/plugin/circle_ci/actions/circleci_get_my_pipelines.rb +100 -0
  34. data/lib/fastlane/plugin/circle_ci/actions/circleci_get_org_summary.rb +113 -0
  35. data/lib/fastlane/plugin/circle_ci/actions/circleci_get_pipeline.rb +104 -0
  36. data/lib/fastlane/plugin/circle_ci/actions/circleci_get_pipeline_by_number.rb +105 -0
  37. data/lib/fastlane/plugin/circle_ci/actions/circleci_get_pipeline_config.rb +92 -0
  38. data/lib/fastlane/plugin/circle_ci/actions/circleci_get_pipeline_definition.rb +99 -0
  39. data/lib/fastlane/plugin/circle_ci/actions/circleci_get_pipeline_definitions.rb +94 -0
  40. data/lib/fastlane/plugin/circle_ci/actions/circleci_get_pipeline_values.rb +91 -0
  41. data/lib/fastlane/plugin/circle_ci/actions/circleci_get_pipeline_workflows.rb +108 -0
  42. data/lib/fastlane/plugin/circle_ci/actions/circleci_get_project_branches.rb +105 -0
  43. data/lib/fastlane/plugin/circle_ci/actions/circleci_get_project_config.rb +104 -0
  44. data/lib/fastlane/plugin/circle_ci/actions/circleci_get_project_workflow_metrics.rb +121 -0
  45. data/lib/fastlane/plugin/circle_ci/actions/circleci_get_trigger.rb +99 -0
  46. data/lib/fastlane/plugin/circle_ci/actions/circleci_get_user_info.rb +83 -0
  47. data/lib/fastlane/plugin/circle_ci/actions/circleci_get_workflow.rb +121 -0
  48. data/lib/fastlane/plugin/circle_ci/actions/circleci_get_workflow_insights.rb +157 -0
  49. data/lib/fastlane/plugin/circle_ci/actions/circleci_get_workflow_job_metrics.rb +123 -0
  50. data/lib/fastlane/plugin/circle_ci/actions/circleci_get_workflow_jobs.rb +109 -0
  51. data/lib/fastlane/plugin/circle_ci/actions/circleci_get_workflow_runs.rb +129 -0
  52. data/lib/fastlane/plugin/circle_ci/actions/circleci_get_workflow_summary.rb +118 -0
  53. data/lib/fastlane/plugin/circle_ci/actions/circleci_get_workflow_test_metrics.rb +115 -0
  54. data/lib/fastlane/plugin/circle_ci/actions/circleci_list_all_pipelines.rb +94 -0
  55. data/lib/fastlane/plugin/circle_ci/actions/circleci_list_contexts.rb +132 -0
  56. data/lib/fastlane/plugin/circle_ci/actions/circleci_list_pipeline_definition_triggers.rb +101 -0
  57. data/lib/fastlane/plugin/circle_ci/actions/circleci_list_pipeline_schedules.rb +99 -0
  58. data/lib/fastlane/plugin/circle_ci/actions/circleci_list_projects.rb +89 -0
  59. data/lib/fastlane/plugin/circle_ci/actions/circleci_list_webhooks.rb +111 -0
  60. data/lib/fastlane/plugin/circle_ci/actions/circleci_rerun_workflow.rb +101 -0
  61. data/lib/fastlane/plugin/circle_ci/actions/circleci_set_env_var.rb +102 -0
  62. data/lib/fastlane/plugin/circle_ci/actions/circleci_trigger_pipeline.rb +130 -0
  63. data/lib/fastlane/plugin/circle_ci/actions/circleci_update_pipeline_definition.rb +127 -0
  64. data/lib/fastlane/plugin/circle_ci/actions/circleci_update_pipeline_schedule.rb +134 -0
  65. data/lib/fastlane/plugin/circle_ci/actions/circleci_update_trigger.rb +114 -0
  66. data/lib/fastlane/plugin/circle_ci/actions/circleci_wait_for_pipeline.rb +152 -0
  67. data/lib/fastlane/plugin/circle_ci/helper/circle_ci_helper.rb +102 -1
  68. data/lib/fastlane/plugin/circle_ci/version.rb +1 -1
  69. metadata +99 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 310a5f9bf0095968820fde6642c4112fc1d6bc449dc9e38b0b408abcd3320613
4
- data.tar.gz: 88089e5f6e51984ae7b8d13545e23bdc5bbe1bf92dc2c550f6d32b90faadfb64
3
+ metadata.gz: f30a30794b17b49d4c75989ea5028a5fd6692dc44ecaeb26c613fd5a62ee9587
4
+ data.tar.gz: c36eceb77e28ec2a2288807992805a56279af4b93a9bb90737f9caa2e1fc933b
5
5
  SHA512:
6
- metadata.gz: 94b9b68f1e9bf5535b08d116d483f07d622c3af2951592f7396432c86bcbe0a331f3cc15d346da6c89058744884d8a79f92bb4348795169eb8063718735c99cf
7
- data.tar.gz: 2d35a6e23b7f2f63bb3c6a3e07530e68c705c68c914a0c703d9742d61d83594d1426e3baec1fcdd4666b1a9e3a04e67ffd270528d0886990bfcf2ce4c2c85100
6
+ metadata.gz: c1732100632defd230826c2e0fdd6e496c74cda78ab4f46d4734d2d4cc7e9c062f4cb3051b3760d23e4988e70a69a4488a89fe508a39020a1795e6e48aad0bfc
7
+ data.tar.gz: d6d189737e89692030d89a0fcae0ccb7113e0c304f735058bdf337bf8b797b23aa9432e2685af7c130f19cbd9bbe03aa54b518802a0cd0fab5d8b859a6952465
data/README.md CHANGED
@@ -14,13 +14,282 @@ fastlane add_plugin circle_ci
14
14
 
15
15
  A fastlane plugin for Circle CI. 🚀
16
16
 
17
- **Note to author:** Add a more detailed description about this plugin here. If your plugin contains multiple actions, make sure to mention them here.
17
+ This plugin provides a set of actions that allow you to interact with CircleCI from your fastlane workflows. It supports both CircleCI API v1.1 (legacy) and API v2 (current).
18
+
19
+ ## Contributors
20
+
21
+ The actions in this plugin were created and enhanced with the assistance of GitHub Copilot, working alongside human developers to provide a comprehensive set of CircleCI integrations for your fastlane workflows.
22
+
23
+ ## Available Actions
24
+
25
+ ### CircleCI API v2 Actions
26
+
27
+ #### Pipeline Management
28
+ - `circleci_trigger_pipeline`: Triggers a new CircleCI pipeline
29
+ - `circleci_get_pipeline`: Gets details of a specific pipeline
30
+ - `circleci_get_pipeline_workflows`: Gets workflows for a pipeline
31
+ - `circleci_wait_for_pipeline`: Waits for a pipeline to complete
32
+ - `circleci_continue_pipeline`: Continues a pipeline that is on hold
33
+ - `circleci_get_pipeline_by_number`: Gets a pipeline by its number
34
+ - `circleci_get_pipeline_config`: Gets the configuration of a pipeline
35
+ - `circleci_get_my_pipelines`: Gets pipelines associated with the current user
36
+ - `circleci_get_pipeline_values`: Gets pipeline parameter values
37
+
38
+ #### Workflow and Job Management
39
+ - `circleci_get_workflow_jobs`: Gets jobs for a workflow
40
+ - `circleci_get_job_details`: Gets detailed information about a job
41
+ - `circleci_get_job_artifacts`: Gets artifacts generated by a job
42
+ - `circleci_download_artifact`: Downloads an artifact to a local path
43
+ - `circleci_download_workflow_artifacts`: Downloads all artifacts from a specific workflow
44
+ - `circleci_approve_job`: Approves a pending approval job in a workflow
45
+ - `circleci_cancel_job`: Cancels a running job
46
+ - `circleci_cancel_workflow`: Cancels a running workflow
47
+ - `circleci_get_job_tests`: Gets test metadata for a job
48
+ - `circleci_get_job_timeseries`: Gets timeseries data for a job
49
+
50
+ #### Environment Variable Management
51
+ - `circleci_get_env_vars`: Gets environment variables for a project
52
+ - `circleci_set_env_var`: Sets an environment variable for a project
53
+ - `circleci_delete_env_var`: Deletes an environment variable from a project
54
+
55
+ #### Context Management
56
+ - `circleci_list_contexts`: Lists available contexts for an owner
57
+ - `circleci_get_context_env_vars`: Gets environment variables for a context
58
+ - `circleci_add_context_env_var`: Adds an environment variable to a context
59
+ - `circleci_delete_context_env_var`: Deletes an environment variable from a context
60
+
61
+ #### Project Management
62
+ - `circleci_add_project_collaborator`: Adds a collaborator to a project
63
+ - `circleci_create_project`: Creates a new CircleCI project
64
+ - `circleci_get_project_branches`: Gets all branches for a project
65
+ - `circleci_get_project_config`: Gets the configuration of a project
66
+ - `circleci_get_project_workflow_metrics`: Gets workflow metrics for a project
67
+
68
+ #### Schedule Management
69
+ - `circleci_create_pipeline_schedule`: Creates a pipeline schedule
70
+ - `circleci_list_pipeline_schedules`: Lists all pipeline schedules for a project
71
+ - `circleci_delete_pipeline_schedule`: Deletes a pipeline schedule
72
+
73
+ #### Webhook Management
74
+ - `circleci_create_webhook`: Creates a webhook for a project
75
+ - `circleci_delete_webhook`: Deletes a webhook
76
+
77
+ #### Pipeline Definition Management
78
+ - `circleci_create_pipeline_definition`: Creates a pipeline definition
79
+ - `circleci_get_pipeline_definition`: Gets details of a pipeline definition
80
+ - `circleci_get_pipeline_definitions`: Lists all pipeline definitions
81
+ - `circleci_delete_pipeline_definition`: Deletes a pipeline definition
82
+ - `circleci_create_pipeline_definition_trigger`: Creates a pipeline definition trigger
83
+ - `circleci_delete_trigger`: Deletes a pipeline trigger
84
+ - `circleci_get_trigger`: Gets information about a pipeline trigger
85
+
86
+ #### Checkout Key Management
87
+ - `circleci_create_checkout_key`: Creates a checkout key for a project
88
+ - `circleci_get_checkout_key`: Gets details of a specific checkout key
89
+ - `circleci_get_checkout_keys`: Lists all checkout keys for a project
90
+ - `circleci_delete_checkout_key`: Deletes a checkout key
91
+
92
+ #### Analytics and Insights
93
+ - `circleci_get_flaky_tests`: Gets flaky tests information for a project
94
+ - `circleci_get_workflow_insights`: Gets insights data for a workflow
95
+ - `circleci_get_workflow_job_metrics`: Gets metrics for jobs in a workflow
96
+ - `circleci_get_workflow_runs`: Gets recent runs of a workflow
97
+ - `circleci_get_workflow_summary`: Gets summary metrics for a workflow
98
+ - `circleci_get_org_summary`: Gets summary metrics for an organization
99
+ - `circleci_get_user_info`: Gets information about the authenticated user
100
+
101
+ ### Legacy API v1.1 Actions
102
+ - `trigger_circle_ci_job`: Triggers a specific job in CircleCI
103
+ - `get_circle_ci_build_status`: Gets the status of a CircleCI build
104
+ - `get_circle_ci_artifacts`: Gets artifacts from a CircleCI build
105
+ - `download_circle_ci_artifact`: Downloads a CircleCI artifact
18
106
 
19
107
  ## Example
20
108
 
21
- Check out the [example `Fastfile`](fastlane/Fastfile) to see how to use this plugin. Try it by cloning the repo, running `fastlane install_plugins` and `bundle exec fastlane test`.
109
+ ### Triggering a Pipeline and Waiting for Completion
110
+
111
+ ```ruby
112
+ # Trigger a pipeline on the main branch
113
+ pipeline = circleci_trigger_pipeline(
114
+ project_slug: "github/myorg/myrepo",
115
+ branch: "main",
116
+ parameters: {
117
+ "deploy_env" => "staging",
118
+ "run_integration_tests" => true
119
+ }
120
+ )
121
+
122
+ # Wait for the pipeline to complete
123
+ result = circleci_wait_for_pipeline(
124
+ pipeline_id: pipeline["id"],
125
+ timeout: 1800, # 30 minutes
126
+ poll_interval: 30 # Check status every 30 seconds
127
+ )
128
+
129
+ if result[:status] == "success"
130
+ UI.success("Pipeline completed successfully!")
131
+ else
132
+ UI.error("Pipeline failed with status: #{result[:status]}")
133
+ end
134
+ ```
135
+
136
+ ### Managing Environment Variables
137
+
138
+ ```ruby
139
+ # Set an environment variable
140
+ circleci_set_env_var(
141
+ project_slug: "github/myorg/myrepo",
142
+ name: "DEPLOY_KEY",
143
+ value: ENV["MY_DEPLOY_KEY"]
144
+ )
145
+
146
+ # Get all environment variables
147
+ env_vars = circleci_get_env_vars(
148
+ project_slug: "github/myorg/myrepo"
149
+ )
150
+
151
+ # Check if a variable exists
152
+ has_api_key = env_vars.any? { |var| var["name"] == "API_KEY" }
153
+ ```
154
+
155
+ ### Working with Contexts
22
156
 
23
- **Note to author:** Please set up a sample project to make it easy for users to explore what your plugin does. Provide everything that is necessary to try out the plugin in this project (including a sample Xcode/Android project if necessary)
157
+ ```ruby
158
+ # List all contexts
159
+ contexts = circleci_list_contexts(
160
+ owner_slug: "github/myorg"
161
+ )
162
+
163
+ # Get a specific context by name
164
+ deploy_context = contexts.find { |ctx| ctx["name"] == "deploy-context" }
165
+
166
+ if deploy_context
167
+ # Add an environment variable to the context
168
+ circleci_add_context_env_var(
169
+ context_id: deploy_context["id"],
170
+ env_var_name: "RELEASE_TOKEN",
171
+ env_var_value: ENV["RELEASE_TOKEN"]
172
+ )
173
+ end
174
+ ```
175
+
176
+ ### Downloading Artifacts
177
+
178
+ ```ruby
179
+ # Download only JSON files (default)
180
+ circleci_download_workflow_artifacts(
181
+ project_slug: "github/myorg/myrepo"
182
+ )
183
+
184
+ # Download only XML files
185
+ circleci_download_workflow_artifacts(
186
+ project_slug: "github/myorg/myrepo",
187
+ file_extensions: "xml"
188
+ )
189
+
190
+ # Download both JSON and XML files
191
+ circleci_download_workflow_artifacts(
192
+ project_slug: "github/myorg/myrepo",
193
+ file_extensions: ["json", "xml"]
194
+ )
195
+
196
+ # Download artifacts from a specific job only
197
+ circleci_download_workflow_artifacts(
198
+ project_slug: "github/myorg/myrepo",
199
+ job_name: "build"
200
+ )
201
+
202
+ # Download all artifacts from a specific workflow
203
+ artifacts_info = circleci_download_workflow_artifacts(
204
+ project_slug: "github/myorg/myrepo",
205
+ branch: "master",
206
+ workflow_name: "test",
207
+ destination_dir: "./artifacts"
208
+ )
209
+
210
+ # Check how many artifacts were downloaded
211
+ UI.message("Downloaded #{artifacts_info[:total_artifacts]} artifacts from #{artifacts_info[:workflow_name]} workflow")
212
+
213
+ # Process downloaded artifacts if needed
214
+ artifacts_info[:downloaded_artifacts].each do |job_artifacts|
215
+ job_name = job_artifacts[:job_name]
216
+ job_artifacts[:artifacts].each do |artifact|
217
+ path = artifact[:download_path]
218
+ # Process artifact files as needed
219
+ puts "Processing #{path} from job #{job_name}"
220
+ end
221
+ end
222
+
223
+ # Get artifacts from a job
224
+ artifacts = circleci_get_job_artifacts(
225
+ project_slug: "github/myorg/myrepo",
226
+ job_number: "123"
227
+ )
228
+
229
+ # Download a specific artifact
230
+ if artifacts.any?
231
+ test_results = artifacts.find { |a| a["path"].end_with?("test-results.xml") }
232
+
233
+ if test_results
234
+ circleci_download_artifact(
235
+ artifact_url: test_results["url"],
236
+ destination_path: "./test-results/circle-results.xml"
237
+ )
238
+ end
239
+ end
240
+ ```
241
+
242
+ ### Working with Pipeline Schedules
243
+
244
+ ```ruby
245
+ # Create a pipeline schedule to run nightly
246
+ circleci_create_pipeline_schedule(
247
+ project_slug: "github/myorg/myrepo",
248
+ name: "Nightly Build",
249
+ description: "Runs every night at midnight",
250
+ timetable: {
251
+ per_hour: 1,
252
+ hours_of_day: [0],
253
+ days_of_week: [1, 2, 3, 4, 5]
254
+ },
255
+ branch: "main",
256
+ parameters: {
257
+ "deploy_env" => "staging"
258
+ }
259
+ )
260
+
261
+ # List all schedules for a project
262
+ schedules = circleci_list_pipeline_schedules(
263
+ project_slug: "github/myorg/myrepo"
264
+ )
265
+
266
+ # Find a specific schedule by name
267
+ nightly_build = schedules.find { |schedule| schedule["name"] == "Nightly Build" }
268
+ ```
269
+
270
+ ### Working with Project Insights
271
+
272
+ ```ruby
273
+ # Get flaky tests for a project
274
+ flaky_tests = circleci_get_flaky_tests(
275
+ project_slug: "github/myorg/myrepo"
276
+ )
277
+
278
+ # Take action on flaky tests
279
+ if flaky_tests["most_failed_tests"].any?
280
+ UI.important("Found #{flaky_tests["most_failed_tests"].count} flaky tests that need attention")
281
+ flaky_tests["most_failed_tests"].each do |test|
282
+ puts " - #{test["test_name"]}: Failed #{test["times_flaked"]} times"
283
+ end
284
+ end
285
+
286
+ # Get workflow metrics
287
+ workflow_metrics = circleci_get_project_workflow_metrics(
288
+ project_slug: "github/myorg/myrepo",
289
+ branch: "main",
290
+ reporting_window: "last-30-days"
291
+ )
292
+ ```
24
293
 
25
294
  ## Run tests for this plugin
26
295
 
@@ -0,0 +1,117 @@
1
+ require 'fastlane/action'
2
+ require_relative '../helper/circle_ci_helper'
3
+
4
+ module Fastlane
5
+ module Actions
6
+ class CircleciAddContextEnvVarAction < Action
7
+ def self.run(params)
8
+ UI.message("Adding environment variable to CircleCI context via API v2...")
9
+
10
+ api_token = params[:api_token]
11
+ context_id = params[:context_id]
12
+ env_var_name = params[:env_var_name]
13
+ env_var_value = params[:env_var_value]
14
+
15
+ # Prepare request body
16
+ body = {
17
+ variable: env_var_name,
18
+ value: env_var_value
19
+ }
20
+
21
+ # Make API request
22
+ result = Helper::CircleCiHelper.put_v2("context/#{context_id}/environment-variable/#{env_var_name}", api_token, body)
23
+
24
+ UI.success("Successfully added environment variable '#{env_var_name}' to context #{context_id}")
25
+
26
+ return result
27
+ end
28
+
29
+ def self.description
30
+ "Adds an environment variable to a CircleCI context using API v2"
31
+ end
32
+
33
+ def self.details
34
+ "This action adds or updates an environment variable in a specific CircleCI context using the CircleCI API v2. Environment variables in contexts are used to securely share configuration across projects."
35
+ end
36
+
37
+ def self.available_options
38
+ [
39
+ FastlaneCore::ConfigItem.new(key: :api_token,
40
+ env_name: "CIRCLE_CI_API_TOKEN",
41
+ description: "API Token for CircleCI API",
42
+ sensitive: true,
43
+ code_gen_sensitive: true,
44
+ is_string: true,
45
+ default_value: ENV["CIRCLE_CI_API_TOKEN"],
46
+ default_value_dynamic: true,
47
+ optional: false),
48
+ FastlaneCore::ConfigItem.new(key: :context_id,
49
+ env_name: "CIRCLE_CI_CONTEXT_ID",
50
+ description: "The ID of the context to add the environment variable to",
51
+ is_string: true,
52
+ optional: false),
53
+ FastlaneCore::ConfigItem.new(key: :env_var_name,
54
+ env_name: "CIRCLE_CI_ENV_VAR_NAME",
55
+ description: "The name of the environment variable",
56
+ is_string: true,
57
+ optional: false),
58
+ FastlaneCore::ConfigItem.new(key: :env_var_value,
59
+ env_name: "CIRCLE_CI_ENV_VAR_VALUE",
60
+ description: "The value of the environment variable",
61
+ sensitive: true,
62
+ code_gen_sensitive: true,
63
+ is_string: true,
64
+ optional: false)
65
+ ]
66
+ end
67
+
68
+ def self.return_value
69
+ "Returns a hash containing the created environment variable information (without the actual value for security)."
70
+ end
71
+
72
+ def self.authors
73
+ ["crazymanish", "copilot"]
74
+ end
75
+
76
+ def self.example_code
77
+ [
78
+ 'circleci_add_context_env_var(
79
+ context_id: "context-uuid",
80
+ env_var_name: "API_KEY",
81
+ env_var_value: "secret-value"
82
+ )',
83
+ '# First find the context, then add a variable to it
84
+ contexts = circleci_list_contexts(
85
+ owner_slug: "github/myorg"
86
+ )
87
+
88
+ # Find the staging context
89
+ staging_context = contexts.find { |c| c["name"] == "staging" }
90
+
91
+ if staging_context
92
+ # Add or update environment variables for staging
93
+ circleci_add_context_env_var(
94
+ context_id: staging_context["id"],
95
+ env_var_name: "DEPLOY_URL",
96
+ env_var_value: "https://staging.example.com"
97
+ )
98
+
99
+ circleci_add_context_env_var(
100
+ context_id: staging_context["id"],
101
+ env_var_name: "STAGE",
102
+ env_var_value: "staging"
103
+ )
104
+ end'
105
+ ]
106
+ end
107
+
108
+ def self.is_supported?(platform)
109
+ true
110
+ end
111
+
112
+ def self.category
113
+ :ci
114
+ end
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,109 @@
1
+ require 'fastlane/action'
2
+ require_relative '../helper/circle_ci_helper'
3
+
4
+ module Fastlane
5
+ module Actions
6
+ module SharedValues
7
+ CIRCLECI_PROJECT_COLLABORATOR = :CIRCLECI_PROJECT_COLLABORATOR
8
+ end
9
+
10
+ class CircleciAddProjectCollaboratorAction < Action
11
+ def self.run(params)
12
+ UI.message("Adding collaborator to CircleCI project via API v2...")
13
+
14
+ api_token = params[:api_token]
15
+ project_slug = params[:project_slug]
16
+ username = params[:username]
17
+
18
+ # Construct the request body
19
+ body = {
20
+ id: username
21
+ }
22
+
23
+ # Make API request
24
+ endpoint = "project/#{project_slug}/user/#{username}"
25
+ result = Helper::CircleCiHelper.post_v2(endpoint, api_token, body)
26
+
27
+ # Store values in lane context
28
+ Actions.lane_context[SharedValues::CIRCLECI_PROJECT_COLLABORATOR] = result
29
+
30
+ UI.success("Successfully added collaborator #{username} to project")
31
+
32
+ return result
33
+ end
34
+
35
+ def self.description
36
+ "Adds a user as a collaborator to a CircleCI project using API v2"
37
+ end
38
+
39
+ def self.details
40
+ "This action adds a user as a collaborator to a CircleCI project using the CircleCI API v2. " +
41
+ "The collaborator will be granted access to view and manage the project based on their role permissions."
42
+ end
43
+
44
+ def self.available_options
45
+ [
46
+ FastlaneCore::ConfigItem.new(key: :api_token,
47
+ env_name: "CIRCLE_CI_API_TOKEN",
48
+ description: "API Token for CircleCI API",
49
+ sensitive: true,
50
+ code_gen_sensitive: true,
51
+ is_string: true,
52
+ default_value: ENV["CIRCLE_CI_API_TOKEN"],
53
+ default_value_dynamic: true,
54
+ optional: false),
55
+ FastlaneCore::ConfigItem.new(key: :project_slug,
56
+ env_name: "CIRCLE_CI_PROJECT_SLUG",
57
+ description: "Project slug in the form of :vcs-type/:org-name/:project-name (e.g. github/myorg/myrepo)",
58
+ is_string: true,
59
+ default_value: ENV["CIRCLE_CI_PROJECT_SLUG"],
60
+ default_value_dynamic: true,
61
+ optional: false),
62
+ FastlaneCore::ConfigItem.new(key: :username,
63
+ env_name: "CIRCLE_CI_COLLABORATOR_USERNAME",
64
+ description: "The username of the user to add as a collaborator",
65
+ is_string: true,
66
+ optional: false)
67
+ ]
68
+ end
69
+
70
+ def self.output
71
+ [
72
+ ['CIRCLECI_PROJECT_COLLABORATOR', 'A hash containing the collaborator data']
73
+ ]
74
+ end
75
+
76
+ def self.return_value
77
+ "Returns a hash containing the collaborator information and their role in the project."
78
+ end
79
+
80
+ def self.authors
81
+ ["crazymanish", "copilot"]
82
+ end
83
+
84
+ def self.example_code
85
+ [
86
+ 'circleci_add_project_collaborator(
87
+ project_slug: "github/myorg/myrepo",
88
+ username: "new-collaborator"
89
+ )',
90
+ '# Add a collaborator and verify they were added
91
+ collaborator = circleci_add_project_collaborator(
92
+ project_slug: "github/myorg/myrepo",
93
+ username: "new-collaborator"
94
+ )
95
+
96
+ UI.message("Added #{collaborator["id"]} with role #{collaborator["role"]}")'
97
+ ]
98
+ end
99
+
100
+ def self.is_supported?(platform)
101
+ true
102
+ end
103
+
104
+ def self.category
105
+ :ci
106
+ end
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,95 @@
1
+ require 'fastlane/action'
2
+ require_relative '../helper/circle_ci_helper'
3
+
4
+ module Fastlane
5
+ module Actions
6
+ class CircleciApproveJobAction < Action
7
+ def self.run(params)
8
+ UI.message("Approving CircleCI job via API v2...")
9
+
10
+ api_token = params[:api_token]
11
+ approval_request_id = params[:approval_request_id]
12
+
13
+ # Make API request with empty body as required by the API
14
+ result = Helper::CircleCiHelper.post_v2("workflow/#{approval_request_id}/approve", api_token, {})
15
+
16
+ UI.success("Successfully approved job with approval request ID #{approval_request_id}")
17
+
18
+ return { success: true, message: "Job approved" }
19
+ end
20
+
21
+ def self.description
22
+ "Approves a pending approval job in a CircleCI workflow using API v2"
23
+ end
24
+
25
+ def self.details
26
+ "This action approves a pending approval job in a CircleCI workflow using the CircleCI API v2. This is useful for automated approval of deployment jobs."
27
+ end
28
+
29
+ def self.available_options
30
+ [
31
+ FastlaneCore::ConfigItem.new(key: :api_token,
32
+ env_name: "CIRCLE_CI_API_TOKEN",
33
+ description: "API Token for CircleCI API",
34
+ sensitive: true,
35
+ code_gen_sensitive: true,
36
+ is_string: true,
37
+ default_value: ENV["CIRCLE_CI_API_TOKEN"],
38
+ default_value_dynamic: true,
39
+ optional: false),
40
+ FastlaneCore::ConfigItem.new(key: :approval_request_id,
41
+ env_name: "CIRCLE_CI_APPROVAL_REQUEST_ID",
42
+ description: "The ID of the approval request to approve",
43
+ is_string: true,
44
+ optional: false)
45
+ ]
46
+ end
47
+
48
+ def self.return_value
49
+ "Returns a hash with success status and a message."
50
+ end
51
+
52
+ def self.authors
53
+ ["crazymanish", "copilot"]
54
+ end
55
+
56
+ def self.example_code
57
+ [
58
+ 'circleci_approve_job(
59
+ approval_request_id: "approval-request-uuid"
60
+ )',
61
+ '# First get workflows for a pipeline, then find and approve any pending approval jobs
62
+ workflows = circleci_get_pipeline_workflows(
63
+ pipeline_id: "some-pipeline-id"
64
+ )
65
+
66
+ # For each workflow
67
+ workflows.each do |workflow|
68
+ # Get jobs for the workflow
69
+ jobs = circleci_get_workflow_jobs(
70
+ workflow_id: workflow["id"]
71
+ )
72
+
73
+ # Find approval jobs that are on_hold
74
+ approval_jobs = jobs.select { |job| job["type"] == "approval" && job["status"] == "on_hold" }
75
+
76
+ # Approve each job
77
+ approval_jobs.each do |job|
78
+ circleci_approve_job(
79
+ approval_request_id: job["id"]
80
+ )
81
+ end
82
+ end'
83
+ ]
84
+ end
85
+
86
+ def self.is_supported?(platform)
87
+ true
88
+ end
89
+
90
+ def self.category
91
+ :ci
92
+ end
93
+ end
94
+ end
95
+ end