Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

feat(bitbucket): support add Bitbucket.org as Git provider (#5135)

Joe Chenc4a4738c704f
diff --git a/backend/plugin/vcs/bitbucket/bitbucket.go b/backend/plugin/vcs/bitbucket/bitbucket.go
index c2c920cfb7..972d9a92ab 100644
--- a/backend/plugin/vcs/bitbucket/bitbucket.go
+++ b/backend/plugin/vcs/bitbucket/bitbucket.go
@@ -78,17 +78,18 @@ func (o oauthResponse) toVCSOAuthToken() *vcs.OAuthToken {
// ExchangeOAuthToken exchanges OAuth content with the provided authorization code.
func (p *Provider) ExchangeOAuthToken(ctx context.Context, instanceURL string, oauthExchange *common.OAuthExchange) (*vcs.OAuthToken, error) {
- form := &url.Values{}
- form.Set("grant_type", "authorization_code")
- form.Set("code", oauthExchange.Code)
+ params := &url.Values{}
+ params.Set("code", oauthExchange.Code)
+ params.Set("redirect_uri", oauthExchange.RedirectURL)
+ params.Set("grant_type", "authorization_code")
url := fmt.Sprintf("%s/site/oauth2/access_token", instanceURL)
- req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, strings.NewReader(form.Encode()))
+ req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, strings.NewReader(params.Encode()))
if err != nil {
return nil, errors.Wrapf(err, "construct POST %s", url)
}
digested := base64.StdEncoding.EncodeToString([]byte(oauthExchange.ClientID + ":" + oauthExchange.ClientSecret))
- req.Header.Set("Authorization", digested)
+ req.Header.Set("Authorization", "Basic "+digested)
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
resp, err := p.client.Do(req)
@@ -1012,7 +1013,7 @@ func tokenRefresher(instanceURL string, oauthCtx oauthContext, refresher common.
return errors.Wrapf(err, "construct POST %s", url)
}
digested := base64.StdEncoding.EncodeToString([]byte(oauthCtx.ClientID + ":" + oauthCtx.ClientSecret))
- req.Header.Set("Authorization", digested)
+ req.Header.Set("Authorization", "Basic "+digested)
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
resp, err := client.Do(req)
diff --git a/backend/plugin/vcs/bitbucket/bitbucket_test.go b/backend/plugin/vcs/bitbucket/bitbucket_test.go
index a4d3561bfc..6799a8d2b9 100644
--- a/backend/plugin/vcs/bitbucket/bitbucket_test.go
+++ b/backend/plugin/vcs/bitbucket/bitbucket_test.go
@@ -18,7 +18,7 @@ import (
func TestProvider_ExchangeOAuthToken(t *testing.T) {
p := newMockProvider(func(r *http.Request) (*http.Response, error) {
assert.Equal(t, "/site/oauth2/access_token", r.URL.Path)
- assert.Equal(t, "dGVzdF9jbGllbnRfaWQ6dGVzdF9jbGllbnRfc2VjcmV0", r.Header.Get("Authorization"))
+ assert.Equal(t, "Basic dGVzdF9jbGllbnRfaWQ6dGVzdF9jbGllbnRfc2VjcmV0", r.Header.Get("Authorization"))
require.NoError(t, r.ParseForm())
assert.Equal(t, "authorization_code", r.PostForm.Get("grant_type"))
diff --git a/backend/server/oauth.go b/backend/server/oauth.go
index 93b36d4471..d063553a3d 100644
--- a/backend/server/oauth.go
+++ b/backend/server/oauth.go
@@ -10,7 +10,6 @@ import (
"github.com/bytebase/bytebase/backend/common"
api "github.com/bytebase/bytebase/backend/legacyapi"
vcsPlugin "github.com/bytebase/bytebase/backend/plugin/vcs"
- _ "github.com/bytebase/bytebase/backend/plugin/vcs/github" // Import to call the init until it is imported from somewhere else
)
func (s *Server) registerOAuthRoutes(g *echo.Group) {
@@ -55,7 +54,7 @@ func (s *Server) registerOAuthRoutes(g *echo.Group) {
}
} else {
vcsType = req.Type
- if vcsType != vcsPlugin.GitLab && vcsType != vcsPlugin.GitHub {
+ if vcsType != vcsPlugin.GitLab && vcsType != vcsPlugin.GitHub && vcsType != vcsPlugin.Bitbucket {
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Unexpected VCS type: %s", vcsType))
}
diff --git a/backend/server/webhook.go b/backend/server/webhook.go
index 81ebd15652..8971ad68ad 100644
--- a/backend/server/webhook.go
+++ b/backend/server/webhook.go
@@ -29,6 +29,7 @@ import (
advisorDB "github.com/bytebase/bytebase/backend/plugin/advisor/db"
"github.com/bytebase/bytebase/backend/plugin/db"
"github.com/bytebase/bytebase/backend/plugin/vcs"
+ _ "github.com/bytebase/bytebase/backend/plugin/vcs/bitbucket" // Import to register the plugin.
"github.com/bytebase/bytebase/backend/plugin/vcs/github"
"github.com/bytebase/bytebase/backend/plugin/vcs/gitlab"
"github.com/bytebase/bytebase/backend/store"
diff --git a/frontend/src/assets/bitbucket-logo.svg b/frontend/src/assets/bitbucket-logo.svg
new file mode 100644
index 0000000000..cdf84686d9
--- /dev/null
+++ b/frontend/src/assets/bitbucket-logo.svg
@@ -0,0 +1 @@
+<svg height="2256" preserveAspectRatio="xMidYMid" width="2500" xmlns="http://www.w3.org/2000/svg" viewBox="-0.9662264221278978 -0.5824607696358868 257.93281329857973 230.8324730411935"><linearGradient id="a" x1="108.633%" x2="46.927%" y1="13.818%" y2="78.776%"><stop offset=".18" stop-color="#0052cc"/><stop offset="1" stop-color="#2684ff"/></linearGradient><g fill="none"><path d="M101.272 152.561h53.449l12.901-75.32H87.06z"/><path d="M8.308 0A8.202 8.202 0 0 0 .106 9.516l34.819 211.373a11.155 11.155 0 0 0 10.909 9.31h167.04a8.202 8.202 0 0 0 8.201-6.89l34.82-213.752a8.202 8.202 0 0 0-8.203-9.514zm146.616 152.768h-53.315l-14.436-75.42h80.67z" fill="#2684ff"/><path d="M244.61 77.242h-76.916l-12.909 75.36h-53.272l-62.902 74.663a11.105 11.105 0 0 0 7.171 2.704H212.73a8.196 8.196 0 0 0 8.196-6.884z" fill="url(#a)"/></g></svg>
\ No newline at end of file
diff --git a/frontend/src/components/Issue/IssueHighlightPanel.vue b/frontend/src/components/Issue/IssueHighlightPanel.vue
index 45d21b2ef7..22b4d42e0c 100644
--- a/frontend/src/components/Issue/IssueHighlightPanel.vue
+++ b/frontend/src/components/Issue/IssueHighlightPanel.vue
@@ -52,6 +52,9 @@
<template v-else-if="pushEvent.vcsType.startsWith('GITHUB')">
<img class="h-4 w-auto" src="../../assets/github-logo.svg" />
</template>
+ <template v-else-if="pushEvent.vcsType.startsWith('BITBUCKET')">
+ <img class="h-4 w-auto" src="../../assets/bitbucket-logo.svg" />
+ </template>
<a :href="vcsBranchUrl" target="_blank" class="normal-link">{{
`${vcsBranch}@${pushEvent.repositoryFullPath}`
}}</a>
@@ -151,6 +154,8 @@ const vcsBranchUrl = computed((): string => {
return `${pushEvent.value.repositoryUrl}/-/tree/${vcsBranch.value}`;
} else if (pushEvent.value.vcsType == "GITHUB") {
return `${pushEvent.value.repositoryUrl}/tree/${vcsBranch.value}`;
+ } else if (pushEvent.value.vcsType == "BITBUCKET") {
+ return `${pushEvent.value.repositoryUrl}/src/${vcsBranch.value}`;
}
}
return "";
diff --git a/frontend/src/components/RepositoryForm.vue b/frontend/src/components/RepositoryForm.vue
index c1382af16a..ffe36e7cd1 100644
--- a/frontend/src/components/RepositoryForm.vue
+++ b/frontend/src/components/RepositoryForm.vue
@@ -9,6 +9,12 @@
<template v-if="vcsType.startsWith('GITLAB')">
<img class="h-4 w-auto" src="../assets/gitlab-logo.svg" />
</template>
+ <template v-if="vcsType.startsWith('GITHUB')">
+ <img class="h-4 w-auto" src="../assets/github-logo.svg" />
+ </template>
+ <template v-if="vcsType.startsWith('BITBUCKET')">
+ <img class="h-4 w-auto" src="../assets/bitbucket-logo.svg" />
+ </template>
</div>
<input
id="gitprovider"
diff --git a/frontend/src/components/RepositorySelectionPanel.vue b/frontend/src/components/RepositorySelectionPanel.vue
index 5097e7232f..25bbf7f121 100644
--- a/frontend/src/components/RepositorySelectionPanel.vue
+++ b/frontend/src/components/RepositorySelectionPanel.vue
@@ -117,6 +117,8 @@ const attentionText = computed((): string => {
return "repository.select-repository-attention-gitlab";
} else if (props.config.vcs.type == "GITHUB") {
return "repository.select-repository-attention-github";
+ } else if (props.config.vcs.type == "BITBUCKET") {
+ return "repository.select-repository-attention-bitbucket";
}
return "";
});
diff --git a/frontend/src/components/RepositorySetupWizard.vue b/frontend/src/components/RepositorySetupWizard.vue
index bc41ddba76..aaa1541292 100644
--- a/frontend/src/components/RepositorySetupWizard.vue
+++ b/frontend/src/components/RepositorySetupWizard.vue
@@ -307,7 +307,10 @@ export default defineComponent({
const createFunc = async () => {
let externalId = state.config.repositoryInfo.externalId;
- if (state.config.vcs.type == "GITHUB") {
+ if (
+ state.config.vcs.type == "GITHUB" ||
+ state.config.vcs.type == "BITBUCKET"
+ ) {
externalId = state.config.repositoryInfo.fullPath;
}
diff --git a/frontend/src/components/RepositoryVCSProviderPanel.vue b/frontend/src/components/RepositoryVCSProviderPanel.vue
index ad6d0462f1..a921059e2e 100644
--- a/frontend/src/components/RepositoryVCSProviderPanel.vue
+++ b/frontend/src/components/RepositoryVCSProviderPanel.vue
@@ -15,6 +15,9 @@
<template v-if="vcs.type.startsWith('GITHUB')">
<img class="h-6 w-auto" src="../assets/github-logo.svg" />
</template>
+ <template v-if="vcs.type.startsWith('BITBUCKET')">
+ <img class="h-6 w-auto" src="../assets/bitbucket-logo.svg" />
+ </template>
<span>{{ vcs.name }}</span>
</button>
</template>
@@ -107,6 +110,8 @@ const selectVCS = (vcs: VCS) => {
let authorizeUrl = `${vcs.instanceUrl}/oauth/authorize`;
if (vcs.type == "GITHUB") {
authorizeUrl = `https://github.com/login/oauth/authorize`;
+ } else if (vcs.type == "BITBUCKET") {
+ authorizeUrl = `https://bitbucket.org/site/oauth2/authorize`;
}
openWindowForOAuth(
authorizeUrl,
diff --git a/frontend/src/components/VCSCard.vue b/frontend/src/components/VCSCard.vue
index 64f2cfa2f8..b279d6a357 100644
--- a/frontend/src/components/VCSCard.vue
+++ b/frontend/src/components/VCSCard.vue
@@ -10,6 +10,9 @@
<template v-if="vcs.type.startsWith('GITHUB')">
<img class="h-6 w-auto" src="../assets/github-logo.svg" />
</template>
+ <template v-if="vcs.type.startsWith('BITBUCKET')">
+ <img class="h-6 w-auto" src="../assets/bitbucket-logo.svg" />
+ </template>
<h3 class="text-lg leading-6 font-medium text-main">
{{ vcs.name }}
</h3>
diff --git a/frontend/src/components/VCSProviderBasicInfoPanel.vue b/frontend/src/components/VCSProviderBasicInfoPanel.vue
index e7bc4b7386..ec01fca39d 100644
--- a/frontend/src/components/VCSProviderBasicInfoPanel.vue
+++ b/frontend/src/components/VCSProviderBasicInfoPanel.vue
@@ -46,6 +46,19 @@
<img class="h-6 w-auto" src="../assets/github-logo.svg" />
<span class="whitespace-nowrap">GitHub.com</span>
</label>
+ <label v-if="isDev" class="radio space-x-2">
+ <input
+ v-model="config.uiType"
+ name="Bitbucket.org"
+ tabindex="-1"
+ type="radio"
+ class="btn"
+ value="BITBUCKET_ORG"
+ @change="changeUIType()"
+ />
+ <img class="h-6 w-auto" src="../assets/bitbucket-logo.svg" />
+ <span class="whitespace-nowrap">Bitbucket.org</span>
+ </label>
</div>
<div class="mt-4 relative">
<div class="relative flex justify-start">
@@ -59,7 +72,7 @@
<div class="h-5 w-5">
<img src="../assets/github-logo.svg" />
</div>
- <label class="whitespace-nowrap">GitHub Enterprise </label>
+ <label class="whitespace-nowrap">GitHub Enterprise</label>
</div>
</div>
<div class="mt-6 pt-6 border-t border-block-border textlabel">
@@ -142,6 +155,8 @@ export default defineComponent({
}
} else if (props.config.type == "GITHUB") {
return "GitHub.com";
+ } else if (props.config.type == "BITBUCKET") {
+ return "Bitbucket.org";
}
return "";
});
@@ -155,6 +170,10 @@ export default defineComponent({
return t(
"gitops.setting.add-git-provider.basic-info.github-instance-url"
);
+ } else if (props.config.type == "BITBUCKET") {
+ return t(
+ "gitops.setting.add-git-provider.basic-info.bitbucket-instance-url"
+ );
}
return "";
});
@@ -168,6 +187,8 @@ export default defineComponent({
}
} else if (props.config.type == "GITHUB") {
return "https://github.com";
+ } else if (props.config.type == "BITBUCKET") {
+ return "https://bitbucket.org";
}
return "";
});
@@ -176,6 +197,7 @@ export default defineComponent({
const instanceUrlDisabled = computed((): boolean => {
return (
props.config.type == "GITHUB" ||
+ props.config.type == "BITBUCKET" ||
(props.config.type == "GITLAB" && props.config.uiType == "GITLAB_COM")
);
});
@@ -231,6 +253,13 @@ export default defineComponent({
props.config.instanceUrl = "https://github.com";
// eslint-disable-next-line vue/no-mutating-props
props.config.name = "GitHub.com";
+ } else if (props.config.uiType == "BITBUCKET_ORG") {
+ // eslint-disable-next-line vue/no-mutating-props
+ props.config.type = "BITBUCKET";
+ // eslint-disable-next-line vue/no-mutating-props
+ props.config.instanceUrl = "https://bitbucket.org";
+ // eslint-disable-next-line vue/no-mutating-props
+ props.config.name = "Bitbucket.org";
}
};
diff --git a/frontend/src/components/VCSProviderConfirmPanel.vue b/frontend/src/components/VCSProviderConfirmPanel.vue
index 7d6aed48ee..5672636d38 100644
--- a/frontend/src/components/VCSProviderConfirmPanel.vue
+++ b/frontend/src/components/VCSProviderConfirmPanel.vue
@@ -41,6 +41,13 @@
<img class="h-6 w-auto" src="../assets/github-logo.svg" />
<div class="whitespace-nowrap">GitHub.com</div>
</div>
+ <div
+ v-else-if="config.uiType == 'BITBUCKET_ORG'"
+ class="flex flex-row items-center space-x-2"
+ >
+ <img class="h-6 w-auto" src="../assets/bitbucket-logo.svg" />
+ <div class="whitespace-nowrap">Bitbucket.org</div>
+ </div>
</dd>
</div>
<div class="grid grid-cols-4 gap-4 px-4 py-2">
diff --git a/frontend/src/components/VCSProviderOAuthPanel.vue b/frontend/src/components/VCSProviderOAuthPanel.vue
index 6235732a07..4ab62424c2 100644
--- a/frontend/src/components/VCSProviderOAuthPanel.vue
+++ b/frontend/src/components/VCSProviderOAuthPanel.vue
@@ -22,6 +22,13 @@
)
}}
</template>
+ <template v-else-if="config.uiType == 'BITBUCKET_ORG'">
+ {{
+ $t(
+ "gitops.setting.add-git-provider.oauth-info.bitbucket-register-oauth-application"
+ )
+ }}
+ </template>
</div>
<ol class="textinfolabel space-y-2">
<template v-if="config.uiType == 'GITLAB_SELF_HOST'">
@@ -262,6 +269,65 @@
}}
</li>
</template>
+ <template v-else-if="config.uiType == 'BITBUCKET_ORG'">
+ <li>
+ 1.
+ {{
+ $t(
+ "gitops.setting.add-git-provider.oauth-info.bitbucket-login-as-admin"
+ )
+ }}
+ </li>
+ <li>
+ 2.
+ {{
+ $t(
+ "gitops.setting.add-git-provider.oauth-info.bitbucket-visit-admin-page"
+ )
+ }}
+ </li>
+ <li>
+ 3.
+ {{
+ $t("gitops.setting.add-git-provider.oauth-info.create-oauth-app")
+ }}
+ <div class="m-4 flex justify-center">
+ <dl
+ class="divide-y divide-block-border border border-block-border shadow rounded-lg"
+ >
+ <div class="grid grid-cols-2 gap-4 px-4 py-2">
+ <dt class="text-sm font-medium text-control-light text-right">
+ Name
+ </dt>
+ <dd class="text-sm text-main">Bytebase</dd>
+ </div>
+ <div class="grid grid-cols-2 gap-4 px-4 py-2 items-center">
+ <dt class="text-sm font-medium text-control-light text-right">
+ Callback URL
+ </dt>
+ <dd class="text-sm text-main items-center flex">
+ {{ redirectUrl() }}
+ <button
+ tabindex="-1"
+ class="ml-1 text-sm font-medium text-control-light hover:bg-gray-100"
+ @click.prevent="copyRedirectURI"
+ >
+ <heroicons-outline:clipboard class="w-6 h-6" />
+ </button>
+ </dd>
+ </div>
+ </dl>
+ </div>
+ </li>
+ <li>
+ 4.
+ {{
+ $t(
+ "gitops.setting.add-git-provider.oauth-info.bitbucket-paste-oauth-info"
+ )
+ }}
+ </li>
+ </template>
</ol>
<div>
<div class="textlabel">
@@ -470,6 +536,10 @@ export default defineComponent({
return t(
"gitops.setting.add-git-provider.oauth-info.github-application-id-error"
);
+ } else if (props.config.type == "BITBUCKET") {
+ return t(
+ "gitops.setting.add-git-provider.oauth-info.bitbucket-application-id-error"
+ );
}
return "";
});
@@ -483,6 +553,10 @@ export default defineComponent({
return t(
"gitops.setting.add-git-provider.oauth-info.github-secret-error"
);
+ } else if (props.config.type == "BITBUCKET") {
+ return t(
+ "gitops.setting.add-git-provider.oauth-info.bitbucket-secret-error"
+ );
}
return "";
});
diff --git a/frontend/src/components/VCSSetupWizard.vue b/frontend/src/components/VCSSetupWizard.vue
index f3c0c7554f..ec6fd68108 100644
--- a/frontend/src/components/VCSSetupWizard.vue
+++ b/frontend/src/components/VCSSetupWizard.vue
@@ -103,7 +103,11 @@ export default defineComponent({
const eventListener = (event: Event) => {
const payload = (event as CustomEvent).detail as OAuthWindowEventPayload;
if (isEmpty(payload.error)) {
- if (state.config.type == "GITLAB" || state.config.type == "GITHUB") {
+ if (
+ state.config.type == "GITLAB" ||
+ state.config.type == "GITHUB" ||
+ state.config.type == "BITBUCKET"
+ ) {
useOAuthStore()
.exchangeVCSToken({
vcsType: state.config.type,
@@ -156,6 +160,8 @@ export default defineComponent({
return t(
"gitops.setting.add-git-provider.github-com-admin-requirement"
);
+ } else if (state.config.type == "BITBUCKET") {
+ return t("gitops.setting.add-git-provider.bitbucket-admin-requirement");
}
return "";
});
@@ -177,6 +183,8 @@ export default defineComponent({
let authorizeUrl = `${state.config.instanceUrl}/oauth/authorize`;
if (state.config.type == "GITHUB") {
authorizeUrl = `https://github.com/login/oauth/authorize`;
+ } else if (state.config.type == "BITBUCKET") {
+ authorizeUrl = `https://bitbucket.org/site/oauth2/authorize`;
}
const newWindow = openWindowForOAuth(
authorizeUrl,
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index 0026f1d3b4..567593b1c4 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -1158,6 +1158,7 @@
"choose-git-provider-contact-workspace-owner": "Contact your Bytebase owner if you want other Git providers to appear here. Bytebase currently supports self-host GitLab EE/CE, and plan to add GitLab.com, and GitHub Enterprise later.",
"select-repository-attention-gitlab": "Bytebase only lists GitLab projects granting you at least the 'Maintainer' role, which allows to configure the project webhook to observe the code push event.",
"select-repository-attention-github": "Bytebase only lists GitHub repositories you have admin permissions, which allows to configure the repository webhook to observe the code push event.",
+ "select-repository-attention-bitbucket": "Bytebase only lists Bitbucket repositories you have admin permissions, which allows to configure the repository webhook to observe the code push event.",
"select-repository-search": "Search repository",
"linked": "Linked repositories"
},
@@ -1329,6 +1330,7 @@
"gitlab-self-host-admin-requirement": "You need to be an Admin of your chosen GitLab instance to configure this. Otherwise, you need to ask your GitLab instance Admin to register Bytebase as a GitLab instance-wide OAuth application, then provide you that Application ID and Secret to fill at the 'OAuth application info' step.",
"gitlab-com-admin-requirement": "Your account needs to have Admin access to any of the repositories to be linked. Usually this account corresponds to a dedicated service user instead of a human user.",
"github-com-admin-requirement": "You need to be an admin of your chosen GitHub organization to configure this. Otherwise, you need to ask your GitHub organization admin to register Bytebase as a GitHub organization-wide OAuth application, then provide you that Application ID and Secret to fill at the 'OAuth application info' step.",
+ "bitbucket-admin-requirement": "You need to be an admin of your chosen Bitbucket workspace to configure this. Otherwise, you need to ask your Bitbucket workspace admin to register Bytebase as a GitHub workspace-wide OAuth application, then provide you that Application ID and Secret to fill at the 'OAuth application info' step.",
"oauth-info-correct": "Verified OAuth info is correct",
"check-oauth-info-match": "Please make sure Secret matches the one from your GitLab instance Application.",
"add-success": "Successfully added Git provider {vcs}",
@@ -1339,6 +1341,7 @@
"gitlab-instance-url": "GitLab instance URL",
"gitlab-instance-url-label": "The VCS instance URL. Make sure this instance and Bytebase are network reachable from each other.",
"github-instance-url": "GitHub instance URL",
+ "bitbucket-instance-url": "Bitbucket instance URL",
"instance-url-error": "Instance URL must begin with https:// or http://",
"display-name": "Display name",
"display-name-label": "An optional display name to help identifying among different configs using the same Git provider."
@@ -1356,6 +1359,10 @@
"github-login-as-admin": "Log in as an organization admin user to the GitHub.com. The account must be an organization admin of the GitHub organization (able to access the organization Settings page).",
"github-visit-admin-page": "Go to the Settings page, then navigate to \"Developer settings > OAuth Apps\" section and click \"Register an application\" button.",
"github-paste-oauth-info": "Paste the Client ID and Client secret from that just created application into fields below.",
+ "bitbucket-register-oauth-application": "Register Bytebase as a Bitbucket workspace-wide OAuth consumer.",
+ "bitbucket-login-as-admin": "Log in as an workspace admin user to the Bitbucket.org. The account must be an workspace admin of the Bitbucket workspace (able to access the workspace Settings page).",
+ "bitbucket-visit-admin-page": "Go to the Settings page, then navigate to \"APPS AND FEATURES > OAuth consumers\" section and click \"Add a consumer\" button.",
+ "bitbucket-paste-oauth-info": "Paste the Key and Secret from that just created consumer into fields below.",
"copy-homepage-url": "Homepage URL copied to clipboard. Paste to the corresponding field on the OAuth application form.",
"copy-redirect-uri": "Redirect URI copied to clipboard. Paste to the corresponding field on the OAuth application form.",
"direct-link": "Direct link",
@@ -1363,7 +1370,9 @@
"gitlab-application-id-error": "Application ID must be a 64-character alphanumeric string",
"gitlab-secret-error": "Secret must be a 64-character alphanumeric string",
"github-application-id-error": "Application ID must be a 20-character alphanumeric string",
- "github-secret-error": "Secret must be a 40-character alphanumeric string"
+ "github-secret-error": "Secret must be a 40-character alphanumeric string",
+ "bitbucket-application-id-error": "Application ID must be a 18-character alphanumeric string",
+ "bitbucket-secret-error": "Secret must be a 32-character alphanumeric string"
},
"confirm": {
"confirm-info": "Confirm the info",
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index fb6c405471..332066a5cc 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -1156,6 +1156,7 @@
"choose-git-provider-contact-workspace-owner": "如果您希望其他 Git 提供方出现在列表中,请联系 Bytebase 实例的所有者。当前 Bytebase 支持自己托管的 GitLab EE/CE,我们之后也会支持 GitLab.com 和 GitHub Enterprise",
"select-repository-attention-gitlab": "Bytebase 仅列出您至少拥有 'Maintainer' 权限的 GitLab 项目。因为只有至少拥有该权限,才能够配置项目的 webhook 用来监听代码推送事件。",
"select-repository-attention-github": "Bytebase 仅列出您拥有管理员权限的 GitHub 仓库。因为只有拥有该权限,才能够配置仓库的 webhook 用来监听代码推送事件。",
+ "select-repository-attention-bitbucket": "Bytebase 仅列出您拥有管理员权限的 Bitbucket 仓库。因为只有拥有该权限,才能够配置仓库的 webhook 用来监听代码推送事件。",
"select-repository-search": "搜索仓库",
"linked": "关联的仓库"
},
@@ -1327,6 +1328,7 @@
"gitlab-self-host-admin-requirement": "您必须是 GitLab 实例的管理员才能进行该配置。否则您需要让您的 GitLab 实例管理员把 Bytebase 先注册为 GitLab 整个实例级别的 OAuth 应用,之后再让对方提供给您注册完成后的应用 ID 以及 Secret,以让您在「OAuth 应用信息」步骤进行填写。",
"gitlab-com-admin-requirement": "您的账号必须对您打算关联的代码仓库拥有管理员权限。通常这个账号对应的是一个专门的服务账号而非个人账号。",
"github-com-admin-requirement": "您必须是 GitHub 组织的管理员才能进行该配置。否则您需要让您的 GitHub 组织管理员把 Bytebase 先注册为组织级别的 OAuth 应用,之后再让对方提供给您注册完成后的应用 ID 以及 Secret,以让您在「OAuth 应用信息」步骤进行填写。",
+ "bitbucket-admin-requirement": "您必须是 Bitbucket 工作空间的管理员才能进行该配置。否则您需要让您的 Bitbucket 工作空间管理员把 Bytebase 先注册为工作空间级别的 OAuth 应用,之后再让对方提供给您注册完成后的应用 ID 以及 Secret,以让您在「OAuth 应用信息」步骤进行填写。",
"oauth-info-correct": "OAuth 信息验证成功",
"check-oauth-info-match": "请确认 Secret 和注册在 GitLab 实例上的应用信息匹配。",
"add-success": "成功添加了 Git 提供方「{vcs}」",
@@ -1337,6 +1339,7 @@
"gitlab-instance-url": "GitLab 实例 URL",
"gitlab-instance-url-label": "VCS 实例 URL。请确认这个实例和 Bytebase 之间网络是互通的。",
"github-instance-url": "GitHub 实例 URL",
+ "bitbucket-instance-url": "Bitbucket 实例 URL",
"instance-url-error": "实例 URL 必须以 https:// or http:// 开头",
"display-name": "展示名称",
"display-name-label": "一个可选的展示名称用以区分不同的 Git 供应方。"
@@ -1354,6 +1357,10 @@
"github-login-as-admin": "以组织管理员身份登录 GitHub.com。这个账号必须是 GitHub 组织的管理员 (能够进入组织 Settings 页面)。",
"github-visit-admin-page": "进入组织 Settings 页面,然后导航到「Developer settings > OAuth Apps」分区,再点击「Register an application」。",
"github-paste-oauth-info": "从刚创建好的应用上粘贴它的 Client ID 和 Client secret 到下面的字段。",
+ "bitbucket-register-oauth-application": "注册 Bytebase 为一个 Bitbucket 工作空间级别 (workspace-wide) 的 OAuth 应用。",
+ "bitbucket-login-as-admin": "以工作空间管理员身份登录 Bitbucket.com。这个账号必须是 Bitbucket 工作空间的管理员 (能够进入工作空间 Settings 页面)。",
+ "bitbucket-visit-admin-page": "进入工作空间 Settings 页面,然后导航到「APPS AND FEATURES > OAuth consumers」分区,再点击「Add a consumer」。",
+ "bitbucket-paste-oauth-info": "从刚创建好的应用上粘贴它的 Key 和 Secret 到下面的字段。",
"copy-homepage-url": "Homepage URL 已复制到剪切板,请粘贴至 OAuth 应用的对应字段内。",
"copy-redirect-uri": "Redirect URI 已复制到剪切板,请粘贴至 OAuth 应用的对应字段内。",
"direct-link": "直达链接",
@@ -1361,7 +1368,9 @@
"gitlab-application-id-error": "应用 ID 必须是 64 个字母长度",
"gitlab-secret-error": "Secret 必须是 64 个字母长度",
"github-application-id-error": "应用 ID 必须是 20 个字母长度",
- "github-secret-error": "Secret 必须是 40 个字母长度"
+ "github-secret-error": "Secret 必须是 40 个字母长度",
+ "bitbucket-application-id-error": "应用 ID 必须是 18 个字母长度",
+ "bitbucket-secret-error": "Secret 必须是 32 个字母长度"
},
"confirm": {
"confirm-info": "确认信息",
diff --git a/frontend/src/store/modules/vcs.ts b/frontend/src/store/modules/vcs.ts
index 5c7b8dee5c..5907babe7b 100644
--- a/frontend/src/store/modules/vcs.ts
+++ b/frontend/src/store/modules/vcs.ts
@@ -21,6 +21,8 @@ function convert(vcs: ResourceObject, includedList: ResourceObject[]): VCS {
}
} else if (vcs.attributes.type == "GITHUB") {
uiType = "GITHUB_COM";
+ } else if (vcs.attributes.type == "BITBUCKET") {
+ uiType = "BITBUCKET_ORG";
}
return {
...(vcs.attributes as Omit<VCS, "id">),
diff --git a/frontend/src/types/oauth.ts b/frontend/src/types/oauth.ts
index 28b8f62177..3ad75ef5a2 100644
--- a/frontend/src/types/oauth.ts
+++ b/frontend/src/types/oauth.ts
@@ -53,6 +53,15 @@ export function openWindowForOAuth(
"oauth",
"location=yes,left=200,top=200,height=640,width=480,scrollbars=yes,status=yes"
);
+ } else if (vcsType == "BITBUCKET") {
+ // Bitbucket OAuth App scopes: https://developer.atlassian.com/cloud/bitbucket/rest/intro/#authentication
+ return window.open(
+ `${endpoint}?client_id=${applicationId}&redirect_uri=${encodeURIComponent(
+ redirectUrl()
+ )}&state=${stateQueryParameter}&response_type=code&scope=repository:write`,
+ "oauth",
+ "location=yes,left=200,top=200,height=640,width=720,scrollbars=yes,status=yes"
+ );
}
// GITLAB
// GitLab OAuth App scopes: https://docs.gitlab.com/ee/integration/oauth_provider.html#authorized-applications
diff --git a/frontend/src/types/repository.ts b/frontend/src/types/repository.ts
index 8f380dcbdd..64071c2445 100644
--- a/frontend/src/types/repository.ts
+++ b/frontend/src/types/repository.ts
@@ -106,6 +106,11 @@ export function baseDirectoryWebUrl(
if (!isEmpty(repository.baseDirectory)) {
url += `/${repository.baseDirectory}`;
}
+ } else if (repository.vcs.type == "BITBUCKET") {
+ url = `${repository.webUrl}/src/${repository.branchFilter}`;
+ if (!isEmpty(repository.baseDirectory)) {
+ url += `/${repository.baseDirectory}`;
+ }
}
if (url) {
// Replace the patterns in the filePathTemplate if possible.
diff --git a/frontend/src/types/sheet.ts b/frontend/src/types/sheet.ts
index a23bf7e787..a5e58e8fc9 100644
--- a/frontend/src/types/sheet.ts
+++ b/frontend/src/types/sheet.ts
@@ -11,7 +11,7 @@ import {
export type SheetVisibility = "PRIVATE" | "PROJECT" | "PUBLIC";
-export type SheetSource = "BYTEBASE" | "GITLAB" | "GITHUB";
+export type SheetSource = "BYTEBASE" | "GITLAB" | "GITHUB" | "BITBUCKET";
export type SheetType = "SQL";
diff --git a/frontend/src/types/vcs.ts b/frontend/src/types/vcs.ts
index 67252a16d8..6643b70763 100644
--- a/frontend/src/types/vcs.ts
+++ b/frontend/src/types/vcs.ts
@@ -2,10 +2,14 @@ import { VCSId } from "./id";
// Backend uses the same ENUM for GitLab/GitHub SaaS and self-hosted. Because they are based on the
// same codebase.
-export type VCSType = "GITLAB" | "GITHUB";
+export type VCSType = "GITLAB" | "GITHUB" | "BITBUCKET";
// When configuring the VCS, we split the SaaS and self-hosted into two types to present optimal UX.
-export type VCSUIType = "GITLAB_SELF_HOST" | "GITLAB_COM" | "GITHUB_COM";
+export type VCSUIType =
+ | "GITLAB_SELF_HOST"
+ | "GITLAB_COM"
+ | "GITHUB_COM"
+ | "BITBUCKET_ORG";
export interface VCSConfig {
type: VCSType;
@@ -91,6 +95,8 @@ export function isValidVCSApplicationIdOrSecret(
return /^[a-zA-Z0-9_]{64}$/.test(str);
} else if (vcsType == "GITHUB") {
return /^[a-zA-Z0-9_]{20}$|^[a-zA-Z0-9_]{40}$/.test(str);
+ } else if (vcsType == "BITBUCKET") {
+ return /^[a-zA-Z0-9_]{18}$|^[a-zA-Z0-9_]{32}$/.test(str);
}
return false;
}
diff --git a/frontend/src/views/MigrationHistoryDetail.vue b/frontend/src/views/MigrationHistoryDetail.vue
index e8fb0b0729..a1449e21b3 100644
--- a/frontend/src/views/MigrationHistoryDetail.vue
+++ b/frontend/src/views/MigrationHistoryDetail.vue
@@ -62,6 +62,12 @@
<template v-if="pushEvent?.vcsType.startsWith('GITLAB')">
<img class="h-4 w-auto" src="../assets/gitlab-logo.svg" />
</template>
+ <template v-if="pushEvent?.vcsType.startsWith('GITHUB')">
+ <img class="h-4 w-auto" src="../assets/github-logo.svg" />
+ </template>
+ <template v-if="pushEvent?.vcsType.startsWith('BITBUCKET')">
+ <img class="h-4 w-auto" src="../assets/bitbucket-logo.svg" />
+ </template>
<a :href="vcsBranchUrl" target="_blank" class="normal-link">
{{ `${vcsBranch}@${pushEvent.repositoryFullPath}` }}
</a>
@@ -366,10 +372,11 @@ export default defineComponent({
const vcsBranch = computed((): string => {
if (pushEvent.value) {
- if (pushEvent.value.vcsType == "GITLAB") {
- const parts = pushEvent.value.ref.split("/");
- return parts[parts.length - 1];
- } else if (pushEvent.value.vcsType == "GITHUB") {
+ if (
+ pushEvent.value.vcsType == "GITLAB" ||
+ pushEvent.value.vcsType == "GITHUB" ||
+ pushEvent.value.vcsType == "BITBUCKET"
+ ) {
const parts = pushEvent.value.ref.split("/");
return parts[parts.length - 1];
}
@@ -383,6 +390,8 @@ export default defineComponent({
return `${pushEvent.value.repositoryUrl}/-/tree/${vcsBranch.value}`;
} else if (pushEvent.value.vcsType == "GITHUB") {
return `${pushEvent.value.repositoryUrl}/tree/${vcsBranch.value}`;
+ } else if (pushEvent.value.vcsType == "BITBUCKET") {
+ return `${pushEvent.value.repositoryUrl}/src/${vcsBranch.value}`;
}
}
return "";
diff --git a/frontend/src/views/SettingWorkspaceVCSDetail.vue b/frontend/src/views/SettingWorkspaceVCSDetail.vue
index 2379fcdf9d..6f31c5c310 100644
--- a/frontend/src/views/SettingWorkspaceVCSDetail.vue
+++ b/frontend/src/views/SettingWorkspaceVCSDetail.vue
@@ -24,6 +24,13 @@
<div class="textlabel whitespace-nowrap">GitHub.com</div>
<img class="h-6 w-auto" src="../assets/github-logo.svg" />
</div>
+ <div
+ v-else-if="vcs.uiType == 'BITBUCKET_ORG'"
+ class="flex flex-row items-center space-x-2"
+ >
+ <div class="textlabel whitespace-nowrap">Bitbucket.org</div>
+ <img class="h-6 w-auto" src="../assets/bitbucket-logo.svg" />
+ </div>
</div>
<div>
@@ -236,7 +243,11 @@ export default defineComponent({
const eventListener = (event: Event) => {
const payload = (event as CustomEvent).detail as OAuthWindowEventPayload;
if (isEmpty(payload.error)) {
- if (vcs.value.type == "GITLAB" || vcs.value.type == "GITHUB") {
+ if (
+ vcs.value.type == "GITLAB" ||
+ vcs.value.type == "GITHUB" ||
+ vcs.value.type == "BITBUCKET"
+ ) {
useOAuthStore()
.exchangeVCSTokenWithID({
code: payload.code,
@@ -291,6 +302,8 @@ export default defineComponent({
let authorizeUrl = `${vcs.value.instanceUrl}/oauth/authorize`;
if (vcs.value.type == "GITHUB") {
authorizeUrl = `https://github.com/login/oauth/authorize`;
+ } else if (vcs.value.type == "BITBUCKET") {
+ authorizeUrl = `https://bitbucket.org/site/oauth2/authorize`;
}
const newWindow = openWindowForOAuth(
authorizeUrl,
@@ -334,6 +347,9 @@ export default defineComponent({
} else if (vcs.value.type == "GITHUB") {
description =
"Please make sure Client secret matches the one from your GitHub.com Application.";
+ } else if (vcs.value.type == "BITBUCKET") {
+ description =
+ "Please make sure Secret matches the one from your Bitbucket.org consumer.";
}
pushNotification({
module: "bytebase",