From d9b386d83baa5495509b31f9c8d1f39812f568d6 Mon Sep 17 00:00:00 2001 From: chaseshak Date: Thu, 10 Aug 2023 11:08:04 -0500 Subject: [PATCH 1/4] Add Bitbucket support --- .github/ISSUE_TEMPLATE/bitbucket.md | 21 +++++++++++++++++++ .github/workflows/issue_ops.yml | 1 + Readme.md | 5 +++++ lib/models/bitbucket/audit.rb | 17 ++++++++++++++++ lib/models/bitbucket/dry_run.rb | 20 ++++++++++++++++++ lib/models/bitbucket/migrate.rb | 22 ++++++++++++++++++++ lib/models/provider.rb | 5 +++-- spec/models/bitbucket/audit_spec.rb | 29 +++++++++++++++++++++++++++ spec/models/bitbucket/dry_run_spec.rb | 21 +++++++++++++++++++ spec/models/bitbucket/migrate_spec.rb | 21 +++++++++++++++++++ 10 files changed, 160 insertions(+), 2 deletions(-) create mode 100644 .github/ISSUE_TEMPLATE/bitbucket.md create mode 100644 lib/models/bitbucket/audit.rb create mode 100644 lib/models/bitbucket/dry_run.rb create mode 100644 lib/models/bitbucket/migrate.rb create mode 100644 spec/models/bitbucket/audit_spec.rb create mode 100644 spec/models/bitbucket/dry_run_spec.rb create mode 100644 spec/models/bitbucket/migrate_spec.rb diff --git a/.github/ISSUE_TEMPLATE/bitbucket.md b/.github/ISSUE_TEMPLATE/bitbucket.md new file mode 100644 index 0000000..4aa5694 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bitbucket.md @@ -0,0 +1,21 @@ +--- +name: Bitbucket +about: Migrate Bitbucket pipelines to GitHub Actions +title: "[Bitbucket]:" +labels: bitbucket +assignees: "" +--- + +## Inputs + +Provide the following required inputs: + +Workspace: _Replace this text with the Bitbucket Workspace to migrate pipelines from._ + +## Available commands + +The following commands can be executed by adding a comment to this issue: + +- `/audit` +- `/dry-run --repository :repository-name` +- `/migrate --repository :repository-name --target-url :github-repository-url` diff --git a/.github/workflows/issue_ops.yml b/.github/workflows/issue_ops.yml index a6f81cf..69e1100 100644 --- a/.github/workflows/issue_ops.yml +++ b/.github/workflows/issue_ops.yml @@ -28,6 +28,7 @@ env: CIRCLE_CI_SOURCE_GITHUB_ACCESS_TOKEN: ${{ secrets.circle_ci_source_github_access_token }} BAMBOO_ACCESS_TOKEN: ${{ secrets.bamboo_access_token }} BAMBOO_INSTANCE_URL: ${{ secrets.bamboo_instance_url }} + BITBUCKET_ACCESS_TOKEN: ${{ secrets.bitbucket_access_token }} jobs: execute-actions-importer: diff --git a/Readme.md b/Readme.md index e6759da..ca52e88 100644 --- a/Readme.md +++ b/Readme.md @@ -101,6 +101,11 @@ The following secrets are required: - `BAMBOO_ACCESS_TOKEN`: The personal access token to access the Bamboo instance. - `BAMBOO_INSTANCE_URL`: The base URL of your Bamboo instance. +### Bitbucket + +The following secrets are required: + +- `BITBUCKET_ACCESS_TOKEN`: The personal access token to access the BitBucket instance. ## Pipeline migration diff --git a/lib/models/bitbucket/audit.rb b/lib/models/bitbucket/audit.rb new file mode 100644 index 0000000..0393eb4 --- /dev/null +++ b/lib/models/bitbucket/audit.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +module Bitbucket + class Audit + include IssueParser + + def initialize(issue_content, _) + @workspace = parameter_from_issue("Workspace", issue_content) + end + + def to_a + return if @workspace.nil? + + [["--workspace", @workspace]] + end + end +end diff --git a/lib/models/bitbucket/dry_run.rb b/lib/models/bitbucket/dry_run.rb new file mode 100644 index 0000000..dc7fbd9 --- /dev/null +++ b/lib/models/bitbucket/dry_run.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +module Bitbucket + class DryRun + include IssueParser + + def initialize(issue_content, command) + @workspace = parameter_from_issue("Workspace", issue_content) + @repository = command.options["repository"] + end + + def to_a + args = [] + args.push(["--workspace", @workspace]) unless @workspace.nil? + args.push(["--repository", @repository]) unless @repository.nil? + + return args unless args.empty? + end + end +end diff --git a/lib/models/bitbucket/migrate.rb b/lib/models/bitbucket/migrate.rb new file mode 100644 index 0000000..9a0f158 --- /dev/null +++ b/lib/models/bitbucket/migrate.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +module Bitbucket + class Migrate + include IssueParser + + def initialize(issue_content, command) + @workspace = parameter_from_issue("Workspace", issue_content) + @repository = command.options["repository"] + @target_url = command.options["target-url"] + end + + def to_a + args = [] + args.push(["--workspace", @workspace]) unless @workspace.nil? + args.push(["--repository", @repository]) unless @repository.nil? + args.push(["--target-url", @target_url]) unless @target_url.nil? + + return args unless args.empty? + end + end +end diff --git a/lib/models/provider.rb b/lib/models/provider.rb index 52ce6bf..9e502c2 100644 --- a/lib/models/provider.rb +++ b/lib/models/provider.rb @@ -11,11 +11,12 @@ class Provider PROVIDER_MAP = { "azure-devops" => ::AzureDevops, + "bamboo" => ::Bamboo, + "bitbucket" => ::Bitbucket, "circle-ci" => ::CircleCI, "gitlab" => ::GitlabCI, "jenkins" => ::Jenkins, - "travis-ci" => ::TravisCI, - "bamboo" => ::Bamboo + "travis-ci" => ::TravisCI }.freeze def initialize(labels) diff --git a/spec/models/bitbucket/audit_spec.rb b/spec/models/bitbucket/audit_spec.rb new file mode 100644 index 0000000..7eaec17 --- /dev/null +++ b/spec/models/bitbucket/audit_spec.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +RSpec.describe Bitbucket::Audit do + let(:audit) { described_class.new(issue_content, nil) } + + describe "#to_a" do + subject { audit.to_a } + + context "when issue_content contains no args" do + let(:issue_content) do + <<~ISSUE + Workspace: + ISSUE + end + + it { is_expected.to be_nil } + end + + context "when issue_content contains a organization" do + let(:issue_content) do + <<~ISSUE + Workspace: testing + ISSUE + end + + it { is_expected.to eq([["--workspace", "testing"]]) } + end + end +end diff --git a/spec/models/bitbucket/dry_run_spec.rb b/spec/models/bitbucket/dry_run_spec.rb new file mode 100644 index 0000000..64bf237 --- /dev/null +++ b/spec/models/bitbucket/dry_run_spec.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +RSpec.describe Bitbucket::DryRun do + let(:dry_run) { described_class.new(issue_content, command) } + let(:command) { Command.new(comment_body) } + + describe "#to_a" do + subject { dry_run.to_a } + let(:issue_content) do + <<~ISSUE + Workspace: testing + ISSUE + end + + context "when the comment body contains a repository" do + let(:comment_body) { "/dry-run --repository repo" } + + it { is_expected.to eq([["--workspace", "testing"], ["--repository", "repo"]]) } + end + end +end diff --git a/spec/models/bitbucket/migrate_spec.rb b/spec/models/bitbucket/migrate_spec.rb new file mode 100644 index 0000000..d7d975c --- /dev/null +++ b/spec/models/bitbucket/migrate_spec.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +RSpec.describe Bitbucket::Migrate do + let(:dry_run) { described_class.new(issue_content, command) } + let(:command) { Command.new(comment_body) } + + describe "#to_a" do + subject { dry_run.to_a } + let(:issue_content) do + <<~ISSUE + Workspace: testing + ISSUE + end + + context "when the comment body contains a repository" do + let(:comment_body) { "/migrate --repository repo --target-url https://github.com/org/repo" } + + it { is_expected.to eq([["--workspace", "testing"], ["--repository", "repo"], ["--target-url", "https://github.com/org/repo"]]) } + end + end +end From 21a62d6a20eafb131c868285195323da334cb9fa Mon Sep 17 00:00:00 2001 From: chaseshak Date: Fri, 11 Aug 2023 13:57:27 -0500 Subject: [PATCH 2/4] Support project key in audit --- lib/models/bitbucket/audit.rb | 10 +++++++--- spec/models/bitbucket/audit_spec.rb | 19 ++++++++++++++++--- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/lib/models/bitbucket/audit.rb b/lib/models/bitbucket/audit.rb index 0393eb4..8d02bbb 100644 --- a/lib/models/bitbucket/audit.rb +++ b/lib/models/bitbucket/audit.rb @@ -4,14 +4,18 @@ module Bitbucket class Audit include IssueParser - def initialize(issue_content, _) + def initialize(issue_content, command) @workspace = parameter_from_issue("Workspace", issue_content) + + @project_key = command.options["project-key"] end def to_a - return if @workspace.nil? + args = [] + args.push(["--workspace", @workspace]) unless @workspace.nil? + args.push(["--project-key", @project_key]) unless @project_key.nil? - [["--workspace", @workspace]] + return args unless args.empty? end end end diff --git a/spec/models/bitbucket/audit_spec.rb b/spec/models/bitbucket/audit_spec.rb index 7eaec17..fb3e606 100644 --- a/spec/models/bitbucket/audit_spec.rb +++ b/spec/models/bitbucket/audit_spec.rb @@ -1,9 +1,11 @@ # frozen_string_literal: true RSpec.describe Bitbucket::Audit do - let(:audit) { described_class.new(issue_content, nil) } - describe "#to_a" do + let(:audit) { described_class.new(issue_content, command) } + let(:command) { Command.new(comment_body) } + let(:comment_body) { "/audit" } + subject { audit.to_a } context "when issue_content contains no args" do @@ -16,7 +18,7 @@ RSpec.describe Bitbucket::Audit do it { is_expected.to be_nil } end - context "when issue_content contains a organization" do + context "when issue_content contains a workspace" do let(:issue_content) do <<~ISSUE Workspace: testing @@ -25,5 +27,16 @@ RSpec.describe Bitbucket::Audit do it { is_expected.to eq([["--workspace", "testing"]]) } end + + context "when the comment body contains a project key" do + let(:issue_content) do + <<~ISSUE + Workspace: testing + ISSUE + end + let(:comment_body) { "/audit --project-key SW" } + + it { is_expected.to eq([["--workspace", "testing"], ["--project-key", "SW"]]) } + end end end From b2dc321f18c766e3cdb805024d5577553dea0134 Mon Sep 17 00:00:00 2001 From: Midhun Nair <107094461+snps-midhunn@users.noreply.github.com> Date: Thu, 14 Sep 2023 14:04:19 +0530 Subject: [PATCH 3/4] Update issue_ops.yml --- .github/workflows/issue_ops.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/issue_ops.yml b/.github/workflows/issue_ops.yml index 69e1100..2ac693b 100644 --- a/.github/workflows/issue_ops.yml +++ b/.github/workflows/issue_ops.yml @@ -13,7 +13,7 @@ defaults: shell: bash env: - GITHUB_INSTANCE_URL: ${{ secrets.GITHUB_INSTANCE_URL || 'https://github.com' }} + GITHUB_INSTANCE_URL: ${{ secrets.GH_INSTANCE_URL || 'https://github.com' }} GITHUB_ACCESS_TOKEN: ${{ secrets.GH_ACCESS_TOKEN }} JENKINS_INSTANCE_URL: ${{ secrets.JENKINS_INSTANCE_URL }} JENKINS_USERNAME: ${{ secrets.jenkins_username }} From 84da28536820a4847a9e4b0db12019ded86e4648 Mon Sep 17 00:00:00 2001 From: Midhun Nair <107094461+snps-midhunn@users.noreply.github.com> Date: Thu, 14 Sep 2023 14:04:44 +0530 Subject: [PATCH 4/4] Update Readme.md --- Readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index ca52e88..5093481 100644 --- a/Readme.md +++ b/Readme.md @@ -35,7 +35,7 @@ The following secrets are required: Optionally, the following secrets can be set: -- `GITHUB_INSTANCE_URL`: The base URL of your GitHub instance (only required if it is **not** ). +- `GH_INSTANCE_URL`: The base URL of your GitHub instance (only required if it is **not** ). ### Azure DevOps