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..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 }} @@ -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..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 @@ -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..8d02bbb --- /dev/null +++ b/lib/models/bitbucket/audit.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +module Bitbucket + class Audit + include IssueParser + + def initialize(issue_content, command) + @workspace = parameter_from_issue("Workspace", issue_content) + + @project_key = command.options["project-key"] + end + + def to_a + args = [] + args.push(["--workspace", @workspace]) unless @workspace.nil? + args.push(["--project-key", @project_key]) unless @project_key.nil? + + return args unless args.empty? + 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..fb3e606 --- /dev/null +++ b/spec/models/bitbucket/audit_spec.rb @@ -0,0 +1,42 @@ +# frozen_string_literal: true + +RSpec.describe Bitbucket::Audit do + 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 + let(:issue_content) do + <<~ISSUE + Workspace: + ISSUE + end + + it { is_expected.to be_nil } + end + + context "when issue_content contains a workspace" do + let(:issue_content) do + <<~ISSUE + Workspace: testing + ISSUE + end + + 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 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