Skip to content

Commit

Permalink
fix: don't include pre-release in latestTag calculation (#427)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoe committed May 5, 2020
1 parent 860c613 commit 1ddb18a
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 7 deletions.
12 changes: 6 additions & 6 deletions __snapshots__/java-bom.js
Original file line number Diff line number Diff line change
Expand Up @@ -836,8 +836,8 @@ This PR was generated with [Release Please](https://github.com/googleapis/releas
`

exports['labels-bom'] = {
"labels": [
"autorelease: pending"
'labels': [
'autorelease: pending'
]
}

Expand Down Expand Up @@ -1614,8 +1614,8 @@ This PR was generated with [Release Please](https://github.com/googleapis/releas
`

exports['labels-bom-snapshot'] = {
"labels": [
"type: process"
'labels': [
'type: process'
]
}

Expand Down Expand Up @@ -2465,7 +2465,7 @@ This PR was generated with [Release Please](https://github.com/googleapis/releas
`

exports['labels-bom-feature'] = {
"labels": [
"autorelease: pending"
'labels': [
'autorelease: pending'
]
}
5 changes: 4 additions & 1 deletion src/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,10 @@ export class GitHub {

async latestTag(perPage = 100): Promise<GitHubTag | undefined> {
const tags: {[version: string]: GitHubTag} = await this.allTags(perPage);
const versions = Object.keys(tags);
const versions = Object.keys(tags).filter(t => {
// remove any pre-releases from the list:
return !t.includes('-');
});
// no tags have been created yet.
if (versions.length === 0) return undefined;

Expand Down
50 changes: 50 additions & 0 deletions test/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,54 @@ describe('GitHub', () => {
req.done();
});
});

describe('latestTag', () => {
it('returns the largest tag, even if sorting is off', async () => {
const req = nock('https://api.github.com')
.get('/repos/fake/fake/tags?per_page=100')
.reply(200, [
{
name: 'v1.2.0',
commit: {sha: 'abc123'},
version: 'v1.2.0',
},
{
name: 'v1.3.0',
commit: {sha: 'abc123'},
version: 'v1.3.0',
},
{
name: 'v1.1.0',
commit: {sha: 'abc123'},
version: 'v1.1.0',
},
]);
const latestTag = await github.latestTag();
expect(latestTag!.version).to.equal('1.3.0');
});

it('does not return pre-releases as latest tag', async () => {
const req = nock('https://api.github.com')
.get('/repos/fake/fake/tags?per_page=100')
.reply(200, [
{
name: 'v1.2.0',
commit: {sha: 'abc123'},
version: 'v1.2.0',
},
{
name: 'v1.3.0-beta.0',
commit: {sha: 'abc123'},
version: 'v1.3.0',
},
{
name: 'v1.1.0',
commit: {sha: 'abc123'},
version: 'v1.1.0',
},
]);
const latestTag = await github.latestTag();
expect(latestTag!.version).to.equal('1.2.0');
});
});
});

0 comments on commit 1ddb18a

Please sign in to comment.