Skip to content
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

feat!: add autorelease: tagged label when creating GitHub release #329

Merged
merged 3 commits into from Jan 2, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
62 changes: 34 additions & 28 deletions __snapshots__/github-release.js
@@ -1,31 +1,8 @@
exports['GitHubRelease extractLatestReleaseNotes extracts appropriate release notes when prior release is patch 1'] = `


### ⚠ BREAKING CHANGES

* temp directory now defaults to setting for report directory

### Features

* default temp directory to report directory ([#102](https://www.github.com/bcoe/c8/issues/102)) ([8602f4a](https://www.github.com/bcoe/c8/commit/8602f4a))
* load .nycrc/.nycrc.json to simplify migration ([#100](https://www.github.com/bcoe/c8/issues/100)) ([bd7484f](https://www.github.com/bcoe/c8/commit/bd7484f))

`

exports['GitHubRelease extractLatestReleaseNotes handles CHANGELOG with new format entries 1'] = `


### Bug Fixes

* candidate issue should only be updated every 15 minutes. ([#70](https://www.github.com/googleapis/release-please/issues/70)) ([edcd1f7](https://www.github.com/googleapis/release-please/commit/edcd1f7))


### Features

* add GitHub action for generating candidate issue ([#69](https://www.github.com/googleapis/release-please/issues/69)) ([6373aed](https://www.github.com/googleapis/release-please/commit/6373aed))
* checkbox based releases ([#77](https://www.github.com/googleapis/release-please/issues/77)) ([1e4193c](https://www.github.com/googleapis/release-please/commit/1e4193c))

`
exports['GitHubRelease createRelease creates and labels release on GitHub 1'] = {
"labels": [
"autorelease: tagged"
]
}

exports['GitHubRelease extractLatestReleaseNotes handles CHANGELOG with old and new format entries 1'] = `

Expand Down Expand Up @@ -65,6 +42,35 @@ exports['GitHubRelease extractLatestReleaseNotes handles CHANGELOG with old form

`

exports['GitHubRelease extractLatestReleaseNotes handles CHANGELOG with new format entries 1'] = `


### Bug Fixes

* candidate issue should only be updated every 15 minutes. ([#70](https://www.github.com/googleapis/release-please/issues/70)) ([edcd1f7](https://www.github.com/googleapis/release-please/commit/edcd1f7))


### Features

* add GitHub action for generating candidate issue ([#69](https://www.github.com/googleapis/release-please/issues/69)) ([6373aed](https://www.github.com/googleapis/release-please/commit/6373aed))
* checkbox based releases ([#77](https://www.github.com/googleapis/release-please/issues/77)) ([1e4193c](https://www.github.com/googleapis/release-please/commit/1e4193c))

`

exports['GitHubRelease extractLatestReleaseNotes extracts appropriate release notes when prior release is patch 1'] = `


### ⚠ BREAKING CHANGES

* temp directory now defaults to setting for report directory

### Features

* default temp directory to report directory ([#102](https://www.github.com/bcoe/c8/issues/102)) ([8602f4a](https://www.github.com/bcoe/c8/commit/8602f4a))
* load .nycrc/.nycrc.json to simplify migration ([#100](https://www.github.com/bcoe/c8/issues/100)) ([bd7484f](https://www.github.com/bcoe/c8/commit/bd7484f))

`

exports['GitHubRelease extractLatestReleaseNotes php-yoshi extracts appropriate release notes, when multiple packages updated 1'] = `

<details><summary>google/cloud-bigquerydatatransfer 0.11.1</summary>
Expand Down
6 changes: 6 additions & 0 deletions src/github-release.ts
Expand Up @@ -18,6 +18,7 @@ import { checkpoint, CheckpointType } from './util/checkpoint';
import { GitHub, GitHubReleasePR, OctokitAPIs } from './github';

const parseGithubRepoUrl = require('parse-github-repo-url');
const GITHUB_RELEASE_LABEL = 'autorelease: tagged';

export interface GitHubReleaseOptions {
label: string;
Expand Down Expand Up @@ -82,6 +83,11 @@ export class GitHubRelease {
gitHubReleasePR.sha,
latestReleaseNotes
);
// Add a label indicating that a release has been created on GitHub,
// but a publication has not yet occurred.
await this.gh.addLabels([GITHUB_RELEASE_LABEL], gitHubReleasePR.number);
// Remove 'autorelease: pending' which indicates a GitHub release
// has not yet been created.
await this.gh.removeLabels(this.labels, gitHubReleasePR.number);
} else {
checkpoint('no recent release PRs found', CheckpointType.Failure);
Expand Down
4 changes: 2 additions & 2 deletions src/github.ts
Expand Up @@ -514,14 +514,14 @@ export class GitHub {
return tags;
}

async addLabels(pr: number, labels: string[]) {
async addLabels(labels: string[], pr: number) {
bcoe marked this conversation as resolved.
Show resolved Hide resolved
checkpoint(
`adding label ${chalk.green(labels.join(','))} to https://github.com/${
this.owner
}/${this.repo}/pull/${pr}`,
CheckpointType.Success
);
this.request(
return this.request(
`POST /repos/:owner/:repo/issues/:issue_number/labels${
this.proxyKey ? `?key=${this.proxyKey}` : ''
}`,
Expand Down
2 changes: 1 addition & 1 deletion src/release-pr.ts
Expand Up @@ -223,7 +223,7 @@ export class ReleasePR {
});
// a return of -1 indicates that PR was not updated.
if (pr > 0) {
await this.gh.addLabels(pr, this.labels);
await this.gh.addLabels(this.labels, pr);
await this.closeStaleReleasePRs(pr, includePackageName);
}
}
Expand Down
47 changes: 46 additions & 1 deletion test/github-release.ts
Expand Up @@ -13,14 +13,59 @@
// limitations under the License.

import { readFileSync } from 'fs';
import { basename, resolve } from 'path';
import { resolve } from 'path';
import * as snapshot from 'snap-shot-it';

import * as nock from 'nock';
nock.disableNetConnect();

import { GitHubRelease } from '../src/github-release';

const fixturesPath = './test/fixtures';

describe('GitHubRelease', () => {
describe('createRelease', () => {
it('creates and labels release on GitHub', async () => {
const release = new GitHubRelease({
label: 'autorelease: pending',
repoUrl: 'googleapis/foo',
packageName: 'foo',
apiUrl: 'https://api.github.com',
});
const requests = nock('https://api.github.com')
.get('/repos/googleapis/foo/pulls?state=closed&per_page=100')
.reply(200, [
{
labels: [{ name: 'autorelease: pending' }],
head: {
label: 'head:release-v1.0.3',
},
number: 1,
merged_at: new Date().toISOString(),
},
])
.get('/repos/googleapis/foo/contents/CHANGELOG.md')
.reply(200, {
content: Buffer.from('#Changelog\n\n## v1.0.3\n\n* entry', 'utf8'),
})
.post('/repos/googleapis/foo/releases')
.reply(200)
.post(
'/repos/googleapis/foo/issues/1/labels',
(body: { [key: string]: string }) => {
snapshot(body);
return true;
}
)
.reply(200)
.delete('/repos/googleapis/foo/issues/1/labels/autorelease:%20pending')
.reply(200);

await release.createRelease();
requests.done();
});
});

describe('extractLatestReleaseNotes', () => {
it('handles CHANGELOG with old and new format entries', () => {
const changelogContent = readFileSync(
Expand Down