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
@@ -0,0 +1,86 @@
1
+ require 'fastlane/action'
2
+ require_relative '../helper/circle_ci_helper'
3
+
4
+ module Fastlane
5
+ module Actions
6
+ class CircleciDeleteEnvVarAction < Action
7
+ def self.run(params)
8
+ UI.message("Deleting environment variable for CircleCI project via API v2...")
9
+
10
+ api_token = params[:api_token]
11
+ project_slug = params[:project_slug]
12
+ name = params[:name]
13
+
14
+ # Make API request
15
+ Helper::CircleCiHelper.delete_v2("project/#{project_slug}/envvar/#{name}", api_token)
16
+
17
+ UI.success("Successfully deleted environment variable '#{name}' for project #{project_slug}")
18
+
19
+ return { success: true, name: name }
20
+ end
21
+
22
+ def self.description
23
+ "Deletes an environment variable for a CircleCI project using API v2"
24
+ end
25
+
26
+ def self.details
27
+ "This action deletes an environment variable for a specific CircleCI project using the CircleCI API v2."
28
+ end
29
+
30
+ def self.available_options
31
+ [
32
+ FastlaneCore::ConfigItem.new(key: :api_token,
33
+ env_name: "CIRCLE_CI_API_TOKEN",
34
+ description: "API Token for CircleCI API",
35
+ sensitive: true,
36
+ code_gen_sensitive: true,
37
+ is_string: true,
38
+ default_value: ENV["CIRCLE_CI_API_TOKEN"],
39
+ default_value_dynamic: true,
40
+ optional: false),
41
+ FastlaneCore::ConfigItem.new(key: :project_slug,
42
+ env_name: "CIRCLE_CI_PROJECT_SLUG",
43
+ description: "Project slug in the form of :vcs-type/:org-name/:project-name (e.g. github/myorg/myrepo)",
44
+ is_string: true,
45
+ default_value: ENV["CIRCLE_CI_PROJECT_SLUG"],
46
+ default_value_dynamic: true,
47
+ optional: false),
48
+ FastlaneCore::ConfigItem.new(key: :name,
49
+ env_name: "CIRCLE_CI_ENV_VAR_NAME",
50
+ description: "Name of the environment variable to delete",
51
+ is_string: true,
52
+ optional: false)
53
+ ]
54
+ end
55
+
56
+ def self.return_value
57
+ "Returns a hash with success status and name of the deleted environment variable."
58
+ end
59
+
60
+ def self.authors
61
+ ["crazymanish", "copilot"]
62
+ end
63
+
64
+ def self.example_code
65
+ [
66
+ 'circleci_delete_env_var(
67
+ project_slug: "github/myorg/myrepo",
68
+ name: "API_KEY"
69
+ )',
70
+ 'circleci_delete_env_var(
71
+ project_slug: "github/myorg/myrepo",
72
+ name: "DEPLOY_ENVIRONMENT"
73
+ )'
74
+ ]
75
+ end
76
+
77
+ def self.is_supported?(platform)
78
+ true
79
+ end
80
+
81
+ def self.category
82
+ :ci
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,91 @@
1
+ require 'fastlane/action'
2
+ require_relative '../helper/circle_ci_helper'
3
+
4
+ module Fastlane
5
+ module Actions
6
+ class CircleciDeletePipelineDefinitionAction < Action
7
+ def self.run(params)
8
+ UI.message("Deleting CircleCI pipeline definition via API v2...")
9
+
10
+ api_token = params[:api_token]
11
+ project_id = params[:project_id]
12
+ pipeline_definition_id = params[:pipeline_definition_id]
13
+
14
+ # Make API request
15
+ result = Helper::CircleCiHelper.delete_v2("projects/#{project_id}/pipeline-definitions/#{pipeline_definition_id}", api_token)
16
+
17
+ UI.success("Successfully deleted pipeline definition with ID #{pipeline_definition_id}")
18
+
19
+ return result
20
+ end
21
+
22
+ def self.description
23
+ "Deletes a pipeline definition from CircleCI using API v2"
24
+ end
25
+
26
+ def self.details
27
+ "This action deletes a specific pipeline definition from CircleCI using the CircleCI API v2."
28
+ end
29
+
30
+ def self.available_options
31
+ [
32
+ FastlaneCore::ConfigItem.new(key: :api_token,
33
+ env_name: "CIRCLE_CI_API_TOKEN",
34
+ description: "API Token for CircleCI API",
35
+ sensitive: true,
36
+ code_gen_sensitive: true,
37
+ is_string: true,
38
+ default_value: ENV["CIRCLE_CI_API_TOKEN"],
39
+ default_value_dynamic: true,
40
+ optional: false),
41
+ FastlaneCore::ConfigItem.new(key: :project_id,
42
+ env_name: "CIRCLE_CI_PROJECT_ID",
43
+ description: "The ID of the CircleCI project",
44
+ is_string: true,
45
+ optional: false),
46
+ FastlaneCore::ConfigItem.new(key: :pipeline_definition_id,
47
+ description: "The ID of the pipeline definition to delete",
48
+ is_string: true,
49
+ optional: false)
50
+ ]
51
+ end
52
+
53
+ def self.return_value
54
+ "Returns a hash with a 'message' key indicating success or failure."
55
+ end
56
+
57
+ def self.authors
58
+ ["crazymanish", "copilot"]
59
+ end
60
+
61
+ def self.example_code
62
+ [
63
+ 'circleci_delete_pipeline_definition(
64
+ project_id: "01234567-89ab-cdef-0123-456789abcdef",
65
+ pipeline_definition_id: "fedcba98-7654-3210-fedc-ba9876543210"
66
+ )',
67
+ '# Get definitions first, then delete one
68
+ definitions = circleci_get_pipeline_definitions(
69
+ project_id: "01234567-89ab-cdef-0123-456789abcdef"
70
+ )
71
+
72
+ # Delete the first definition
73
+ if definitions["items"].any?
74
+ circleci_delete_pipeline_definition(
75
+ project_id: "01234567-89ab-cdef-0123-456789abcdef",
76
+ pipeline_definition_id: definitions["items"].first["id"]
77
+ )
78
+ end'
79
+ ]
80
+ end
81
+
82
+ def self.is_supported?(platform)
83
+ true
84
+ end
85
+
86
+ def self.category
87
+ :ci
88
+ end
89
+ end
90
+ end
91
+ 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 CircleciDeletePipelineScheduleAction < Action
7
+ def self.run(params)
8
+ UI.message("Deleting CircleCI pipeline schedule via API v2...")
9
+
10
+ api_token = params[:api_token]
11
+ project_slug = params[:project_slug]
12
+ schedule_id = params[:schedule_id]
13
+
14
+ # Make API request
15
+ Helper::CircleCiHelper.delete_v2("project/#{project_slug}/schedule/#{schedule_id}", api_token)
16
+
17
+ UI.success("Successfully deleted pipeline schedule with ID #{schedule_id}")
18
+
19
+ return { success: true, schedule_id: schedule_id }
20
+ end
21
+
22
+ def self.description
23
+ "Deletes a pipeline schedule for a CircleCI project using API v2"
24
+ end
25
+
26
+ def self.details
27
+ "This action deletes a specific pipeline schedule for a CircleCI project using the CircleCI API v2."
28
+ end
29
+
30
+ def self.available_options
31
+ [
32
+ FastlaneCore::ConfigItem.new(key: :api_token,
33
+ env_name: "CIRCLE_CI_API_TOKEN",
34
+ description: "API Token for CircleCI API",
35
+ sensitive: true,
36
+ code_gen_sensitive: true,
37
+ is_string: true,
38
+ default_value: ENV["CIRCLE_CI_API_TOKEN"],
39
+ default_value_dynamic: true,
40
+ optional: false),
41
+ FastlaneCore::ConfigItem.new(key: :project_slug,
42
+ env_name: "CIRCLE_CI_PROJECT_SLUG",
43
+ description: "Project slug in the form of :vcs-type/:org-name/:project-name (e.g. github/myorg/myrepo)",
44
+ is_string: true,
45
+ default_value: ENV["CIRCLE_CI_PROJECT_SLUG"],
46
+ default_value_dynamic: true,
47
+ optional: false),
48
+ FastlaneCore::ConfigItem.new(key: :schedule_id,
49
+ env_name: "CIRCLE_CI_SCHEDULE_ID",
50
+ description: "The ID of the schedule to delete",
51
+ is_string: true,
52
+ optional: false)
53
+ ]
54
+ end
55
+
56
+ def self.return_value
57
+ "Returns a hash with success status and the deleted schedule ID."
58
+ end
59
+
60
+ def self.authors
61
+ ["crazymanish", "copilot"]
62
+ end
63
+
64
+ def self.example_code
65
+ [
66
+ 'circleci_delete_pipeline_schedule(
67
+ project_slug: "github/myorg/myrepo",
68
+ schedule_id: "0000-1111-2222-3333"
69
+ )',
70
+ '# First get all schedules, then delete a specific one
71
+ schedules = circleci_list_pipeline_schedules(
72
+ project_slug: "github/myorg/myrepo"
73
+ )
74
+
75
+ nightly_build = schedules.find { |schedule| schedule["name"] == "Nightly Build" }
76
+
77
+ if nightly_build
78
+ circleci_delete_pipeline_schedule(
79
+ project_slug: "github/myorg/myrepo",
80
+ schedule_id: nightly_build["id"]
81
+ )
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
@@ -0,0 +1,92 @@
1
+ require 'fastlane/action'
2
+ require_relative '../helper/circle_ci_helper'
3
+
4
+ module Fastlane
5
+ module Actions
6
+ class CircleciDeleteTriggerAction < Action
7
+ def self.run(params)
8
+ UI.message("Deleting CircleCI trigger via API v2...")
9
+
10
+ api_token = params[:api_token]
11
+ project_id = params[:project_id]
12
+ trigger_id = params[:trigger_id]
13
+
14
+ # Make API request
15
+ result = Helper::CircleCiHelper.delete_v2("projects/#{project_id}/triggers/#{trigger_id}", api_token)
16
+
17
+ UI.success("Successfully deleted trigger with ID #{trigger_id}")
18
+
19
+ return result
20
+ end
21
+
22
+ def self.description
23
+ "Deletes a trigger from CircleCI using API v2"
24
+ end
25
+
26
+ def self.details
27
+ "This action deletes a specific trigger from CircleCI using the CircleCI API v2."
28
+ end
29
+
30
+ def self.available_options
31
+ [
32
+ FastlaneCore::ConfigItem.new(key: :api_token,
33
+ env_name: "CIRCLE_CI_API_TOKEN",
34
+ description: "API Token for CircleCI API",
35
+ sensitive: true,
36
+ code_gen_sensitive: true,
37
+ is_string: true,
38
+ default_value: ENV["CIRCLE_CI_API_TOKEN"],
39
+ default_value_dynamic: true,
40
+ optional: false),
41
+ FastlaneCore::ConfigItem.new(key: :project_id,
42
+ env_name: "CIRCLE_CI_PROJECT_ID",
43
+ description: "The ID of the CircleCI project",
44
+ is_string: true,
45
+ optional: false),
46
+ FastlaneCore::ConfigItem.new(key: :trigger_id,
47
+ description: "The ID of the trigger to delete",
48
+ is_string: true,
49
+ optional: false)
50
+ ]
51
+ end
52
+
53
+ def self.return_value
54
+ "Returns a hash with a 'message' key indicating success or failure."
55
+ end
56
+
57
+ def self.authors
58
+ ["crazymanish", "copilot"]
59
+ end
60
+
61
+ def self.example_code
62
+ [
63
+ 'circleci_delete_trigger(
64
+ project_id: "01234567-89ab-cdef-0123-456789abcdef",
65
+ trigger_id: "fedcba98-7654-3210-fedc-ba9876543210"
66
+ )',
67
+ '# Get triggers first, then delete one
68
+ triggers = circleci_list_pipeline_definition_triggers(
69
+ project_id: "01234567-89ab-cdef-0123-456789abcdef",
70
+ pipeline_definition_id: "aaaabbbb-cccc-dddd-eeee-ffff00001111"
71
+ )
72
+
73
+ # Delete the first trigger
74
+ if triggers["items"].any?
75
+ circleci_delete_trigger(
76
+ project_id: "01234567-89ab-cdef-0123-456789abcdef",
77
+ trigger_id: triggers["items"].first["id"]
78
+ )
79
+ end'
80
+ ]
81
+ end
82
+
83
+ def self.is_supported?(platform)
84
+ true
85
+ end
86
+
87
+ def self.category
88
+ :ci
89
+ end
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,86 @@
1
+ require 'fastlane/action'
2
+ require_relative '../helper/circle_ci_helper'
3
+
4
+ module Fastlane
5
+ module Actions
6
+ class CircleciDeleteWebhookAction < Action
7
+ def self.run(params)
8
+ UI.message("Deleting CircleCI webhook via API v2...")
9
+
10
+ api_token = params[:api_token]
11
+ webhook_id = params[:webhook_id]
12
+
13
+ # Make API request
14
+ Helper::CircleCiHelper.delete_v2("webhook/#{webhook_id}", api_token)
15
+
16
+ UI.success("Successfully deleted webhook with ID #{webhook_id}")
17
+
18
+ return { success: true, webhook_id: webhook_id }
19
+ end
20
+
21
+ def self.description
22
+ "Deletes a webhook from CircleCI using API v2"
23
+ end
24
+
25
+ def self.details
26
+ "This action deletes a specific webhook from CircleCI using the CircleCI API v2."
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: :webhook_id,
41
+ env_name: "CIRCLE_CI_WEBHOOK_ID",
42
+ description: "The ID of the webhook to delete",
43
+ is_string: true,
44
+ optional: false)
45
+ ]
46
+ end
47
+
48
+ def self.return_value
49
+ "Returns a hash with success status and the deleted webhook ID."
50
+ end
51
+
52
+ def self.authors
53
+ ["crazymanish", "copilot"]
54
+ end
55
+
56
+ def self.example_code
57
+ [
58
+ 'circleci_delete_webhook(
59
+ webhook_id: "webhook-uuid"
60
+ )',
61
+ '# First get all webhooks, then delete a specific one
62
+ webhooks = circleci_list_webhooks(
63
+ scope_id: "project-uuid",
64
+ scope_type: "project"
65
+ )
66
+
67
+ slack_webhook = webhooks.find { |webhook| webhook["name"].include?("Slack") }
68
+
69
+ if slack_webhook
70
+ circleci_delete_webhook(
71
+ webhook_id: slack_webhook["id"]
72
+ )
73
+ end'
74
+ ]
75
+ end
76
+
77
+ def self.is_supported?(platform)
78
+ true
79
+ end
80
+
81
+ def self.category
82
+ :ci
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,119 @@
1
+ require 'fastlane/action'
2
+ require 'faraday'
3
+ require 'faraday/follow_redirects'
4
+ require 'fileutils'
5
+ require_relative '../helper/circle_ci_helper'
6
+
7
+ module Fastlane
8
+ module Actions
9
+ class CircleciDownloadArtifactAction < Action
10
+ def self.run(params)
11
+ UI.message("Downloading CircleCI artifact...")
12
+
13
+ artifact_url = params[:artifact_url]
14
+ destination_path = params[:destination_path]
15
+ api_token = params[:api_token]
16
+
17
+ # Ensure the directory exists
18
+ FileUtils.mkdir_p(File.dirname(destination_path))
19
+
20
+ # Configure Faraday
21
+ conn = Faraday.new do |f|
22
+ f.headers['Circle-Token'] = api_token if api_token
23
+ f.response :follow_redirects
24
+ f.adapter Faraday.default_adapter
25
+ end
26
+
27
+ # Download the file
28
+ begin
29
+ response = conn.get(artifact_url)
30
+
31
+ if response.status >= 200 && response.status < 300
32
+ # Write the response body to the destination file
33
+ File.binwrite(destination_path, response.body)
34
+ UI.success("Successfully downloaded artifact to #{destination_path}")
35
+ return { success: true, path: destination_path }
36
+ else
37
+ UI.error("Failed to download artifact: HTTP #{response.status} - #{response.body}")
38
+ return { success: false, error: "HTTP #{response.status}" }
39
+ end
40
+ rescue => e
41
+ UI.error("Error downloading artifact: #{e.message}")
42
+ return { success: false, error: e.message }
43
+ end
44
+ end
45
+
46
+ def self.description
47
+ "Downloads an artifact from CircleCI"
48
+ end
49
+
50
+ def self.details
51
+ "This action downloads an artifact from CircleCI to a local path. It works with artifacts from the CircleCI API v2."
52
+ end
53
+
54
+ def self.available_options
55
+ [
56
+ FastlaneCore::ConfigItem.new(key: :artifact_url,
57
+ env_name: "CIRCLE_CI_ARTIFACT_URL",
58
+ description: "URL of the artifact to download",
59
+ is_string: true,
60
+ optional: false),
61
+ FastlaneCore::ConfigItem.new(key: :destination_path,
62
+ env_name: "CIRCLE_CI_ARTIFACT_DESTINATION",
63
+ description: "Local path where the artifact should be saved",
64
+ is_string: true,
65
+ optional: false),
66
+ FastlaneCore::ConfigItem.new(key: :api_token,
67
+ env_name: "CIRCLE_CI_API_TOKEN",
68
+ description: "API Token for CircleCI API (only needed for private artifacts)",
69
+ sensitive: true,
70
+ code_gen_sensitive: true,
71
+ is_string: true,
72
+ default_value: ENV["CIRCLE_CI_API_TOKEN"],
73
+ default_value_dynamic: true,
74
+ optional: true)
75
+ ]
76
+ end
77
+
78
+ def self.return_value
79
+ "Returns a hash with success status and the path of the downloaded artifact or error information."
80
+ end
81
+
82
+ def self.authors
83
+ ["crazymanish", "copilot"]
84
+ end
85
+
86
+ def self.example_code
87
+ [
88
+ 'circleci_download_artifact(
89
+ artifact_url: "https://dl.circleci.com/private/output/job/12345/artifacts/0/path/to/artifact.zip",
90
+ destination_path: "./artifacts/build.zip"
91
+ )',
92
+ '# First get artifacts, then download a specific one
93
+ artifacts = circleci_get_job_artifacts(
94
+ project_slug: "github/myorg/myrepo",
95
+ job_number: "123"
96
+ )
97
+
98
+ # Find and download a test results artifact
99
+ test_results = artifacts.find { |a| a["path"].end_with?("test-results.xml") }
100
+
101
+ if test_results
102
+ circleci_download_artifact(
103
+ artifact_url: test_results["url"],
104
+ destination_path: "./test-results/circle-results.xml"
105
+ )
106
+ end'
107
+ ]
108
+ end
109
+
110
+ def self.is_supported?(platform)
111
+ true
112
+ end
113
+
114
+ def self.category
115
+ :ci
116
+ end
117
+ end
118
+ end
119
+ end