Skip to content

Misc bug fixes for Bitbucket #8298

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export class BitbucketAppSupport {
const oauthToken = token.value;

const api = new Bitbucket({
notice: false,
baseUrl: `https://api.${params.provider.host}/2.0`,
auth: {
token: oauthToken
Expand Down
20 changes: 11 additions & 9 deletions components/server/ee/src/prebuilds/bitbucket-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ export class BitbucketApp {
}
const user = await this.findUser({ span }, secretToken);
if (!user) {
res.statusCode = 503;
// If the webhook installer is no longer found in Gitpod's DB
// we should send a UNAUTHORIZED signal.
res.statusCode = 401;
res.send();
return;
}
Expand All @@ -45,13 +47,13 @@ export class BitbucketApp {
await this.handlePushHook({ span }, data, user);
}
} else {
console.log(`Ignoring unsupported bitbucket event: ${req.header('X-Event-Key')}`);
console.warn(`Ignoring unsupported bitbucket event: ${req.header('X-Event-Key')}`);
}
res.send('OK');
} catch (err) {
console.error(`Couldn't handle request.`, req.headers, req.body);
console.error(err);
res.sendStatus(500);
console.error(`Couldn't handle request.`, err, { headers: req.headers, reqBody: req.body });
} finally {
// we always respond with OK, when we received a valid event.
res.sendStatus(200);
}
});
}
Expand Down Expand Up @@ -89,7 +91,7 @@ export class BitbucketApp {
span.setTag('contextURL', contextURL);
const config = await this.prebuildManager.fetchConfig({ span }, user, contextURL);
if (!this.prebuildManager.shouldPrebuild(config)) {
console.log('No config. No prebuild.');
console.log('Bitbucket push event: No config. No prebuild.');
return undefined;
}

Expand Down Expand Up @@ -159,7 +161,7 @@ export class BitbucketApp {
function toData(body: BitbucketPushHook): ParsedRequestData | undefined {
const branchName = body.push.changes[0]?.new?.name;
const commitHash = body.push.changes[0]?.new?.target?.hash;
if (!branchName || !commitHash){
if (!branchName || !commitHash) {
return undefined;
}
const result = {
Expand All @@ -169,7 +171,7 @@ function toData(body: BitbucketPushHook): ParsedRequestData | undefined {
gitCloneUrl: body.repository.links.html.href + '.git'
}
if (!result.commitHash || !result.repoUrl) {
console.error('unexpected request body.', body);
console.error('Bitbucket push event: unexpected request body.', body);
throw new Error('Unexpected request body.');
}
return result;
Expand Down
2 changes: 1 addition & 1 deletion components/server/ee/src/prebuilds/bitbucket-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class BitbucketService extends RepositoryService {
}
console.log('Installed Bitbucket Webhook for ' + cloneUrl);
} catch (error) {
console.error(error);
console.error('Failed to install Bitbucket webhook for ' + cloneUrl, error);
}
}

Expand Down
2 changes: 2 additions & 0 deletions components/server/src/bitbucket/bitbucket-api-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export class BitbucketApiFactory {

protected createBitbucket(baseUrl: string, token: Token): APIClient {
return new Bitbucket({
notice: false,
baseUrl,
auth: {
token: token.value
Expand All @@ -44,6 +45,7 @@ export class BasicAuthBitbucketApiFactory extends BitbucketApiFactory {
protected createBitbucket(baseUrl: string, token: Token): APIClient {

return new Bitbucket({
notice: false,
baseUrl,
auth: {
username: token.username!,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export class BitbucketAuthProvider extends GenericAuthProvider {
try {

const options = {
notice: false,
auth: { token: accessToken },
baseUrl: `https://api.${this.params.host}/2.0`,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export class BitbucketTokenValidator implements IGitTokenValidator {
};

const options = {
notice: false,
auth: { token: token },
baseUrl: `https://api.${host}/2.0`,
};
Expand Down