Skip to content
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
12 changes: 7 additions & 5 deletions packages/build/src/github-repo.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ describe('GithubRepo', () => {

beforeEach(() => {
octokit = {
paginate: sinon.stub().resolves([{ id: '123', tag_name: 'v0.0.6', draft: true }]),
paginate: sinon.stub().resolves([{ id: '123', tag_name: 'v0.0.6', draft: true, html_url: 'releaseUrl' }]),
repos: {
updateRelease: sinon.stub().resolves()
}
Expand All @@ -414,8 +414,9 @@ describe('GithubRepo', () => {
});

it('finds the release corresponding to config.version and sets draft to false', async() => {
await githubRepo.promoteRelease({ version: '0.0.6' } as any);
const releaseUrl = await githubRepo.promoteRelease({ version: '0.0.6' } as any);

expect(releaseUrl).to.equal('releaseUrl');
expect(octokit.repos.updateRelease).to.have.been.calledWith({
draft: false,
owner: 'mongodb-js',
Expand Down Expand Up @@ -668,15 +669,16 @@ describe('GithubRepo', () => {
...githubRepo.repo,
base: 'toBase',
head: 'fromBranch',
title: 'PR'
title: 'PR',
body: 'description'
}).resolves({
data: {
number: 42,
html_url: 'url'
}
});

const result = await githubRepo.createPullRequest('PR', 'fromBranch', 'toBase');
const result = await githubRepo.createPullRequest('PR', 'description', 'fromBranch', 'toBase');
expect(result.prNumber).to.equal(42);
expect(result.url).to.equal('url');
});
Expand All @@ -698,7 +700,7 @@ describe('GithubRepo', () => {
githubRepo = getTestGithubRepo(octokit);
});

it('creates a proper PR', async() => {
it('merges a PR', async() => {
mergePullRequest.withArgs({
...githubRepo.repo,
pull_number: 42
Expand Down
11 changes: 7 additions & 4 deletions packages/build/src/github-repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type ReleaseDetails = {
upload_url: string;
id: number;
assets?: ReleaseAsset[]
html_url: string;
};

type ReleaseAsset = {
Expand Down Expand Up @@ -174,7 +175,7 @@ export class GithubRepo {
return releases.find(({ tag_name }) => tag_name === tag);
}

async promoteRelease(config: Config): Promise<void> {
async promoteRelease(config: Config): Promise<string> {
const tag = `v${config.version}`;

const releaseDetails = await this.getReleaseByTag(tag);
Expand All @@ -185,7 +186,7 @@ export class GithubRepo {

if (!releaseDetails.draft) {
console.info(`Release for ${tag} is already public.`);
return;
return releaseDetails.html_url;
}

const params = {
Expand All @@ -195,6 +196,7 @@ export class GithubRepo {
};

await this.octokit.repos.updateRelease(params);
return releaseDetails.html_url;
}

/**
Expand Down Expand Up @@ -279,12 +281,13 @@ export class GithubRepo {
};
}

async createPullRequest(title: string, fromBranch: string, toBaseBranch: string): Promise<{prNumber: number, url: string}> {
async createPullRequest(title: string, description: string, fromBranch: string, toBaseBranch: string): Promise<{prNumber: number, url: string}> {
const response = await this.octokit.pulls.create({
...this.repo,
base: toBaseBranch,
head: fromBranch,
title
title,
body: description
});

return {
Expand Down
7 changes: 5 additions & 2 deletions packages/build/src/homebrew/publish-to-homebrew.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,14 @@ describe('Homebrew publish-to-homebrew', () => {

createPullRequest
.rejects()
.withArgs('mongosh 1.0.0', 'mongodb-js:new-branch', 'master')
.withArgs('mongosh 1.0.0', sinon.match.string, 'mongodb-js:new-branch', 'master')
.resolves({ prNumber: 42, url: 'url' });

await publishToHomebrew(
homebrewCore,
homebrewFork,
'1.0.0',
'githubRelease',
httpsSha256,
generateFormula,
updateHomebrewFork
Expand Down Expand Up @@ -100,6 +101,7 @@ describe('Homebrew publish-to-homebrew', () => {
homebrewCore,
homebrewFork,
'1.0.0',
'githubRelease',
httpsSha256,
generateFormula,
updateHomebrewFork
Expand Down Expand Up @@ -134,13 +136,14 @@ describe('Homebrew publish-to-homebrew', () => {

createPullRequest
.rejects()
.withArgs('mongosh 1.0.0', 'mongodb-js:new-branch', 'master')
.withArgs('mongosh 1.0.0', sinon.match.string, 'mongodb-js:new-branch', 'master')
.resolves({ prNumber: 42, url: 'url' });

await publishToHomebrew(
homebrewCore,
homebrewFork,
'1.0.0',
'githubRelease',
httpsSha256,
generateFormula,
updateHomebrewFork
Expand Down
10 changes: 9 additions & 1 deletion packages/build/src/homebrew/publish-to-homebrew.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export async function publishToHomebrew(
homebrewCore: GithubRepo,
homebrewCoreFork: GithubRepo,
packageVersion: string,
githubReleaseLink: string,
httpsSha256Fn = httpsSha256,
generateFormulaFn = generateUpdatedFormula,
updateHomebrewForkFn = updateHomebrewFork
Expand All @@ -32,6 +33,13 @@ export async function publishToHomebrew(
return;
}

const pr = await homebrewCore.createPullRequest(`mongosh ${packageVersion}`, `${homebrewCoreFork.repo.owner}:${forkBranch}`, 'master');
const description = `This PR was created automatically and bumps \`mongosh\` to the latest published version \`${packageVersion}\`.\n\nFor additional details see ${githubReleaseLink}.`;

const pr = await homebrewCore.createPullRequest(
`mongosh ${packageVersion}`,
description,
`${homebrewCoreFork.repo.owner}:${forkBranch}`,
'master'
);
console.info(`Created PR #${pr.prNumber} in ${homebrewCore.repo.owner}/${homebrewCore.repo.repo}: ${pr.url}`);
}
5 changes: 3 additions & 2 deletions packages/build/src/run-publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export async function runPublish(
config.downloadCenterAwsSecret || ''
);

await mongoshGithubRepo.promoteRelease(config);
const releaseUrl = await mongoshGithubRepo.promoteRelease(config);

// ensures the segment api key to be present in the published packages
await writeAnalyticsConfig(
Expand All @@ -75,7 +75,8 @@ export async function runPublish(
await publishToHomebrew(
homebrewCoreGithubRepo,
mongodbHomebrewForkGithubRepo,
config.version
config.version,
releaseUrl
);

console.info('mongosh: finished release process.');
Expand Down