Skip to content

Commit

Permalink
Fix version calculation based on PR labels (#1258)
Browse files Browse the repository at this point in the history
* Fix version calulation based on PR labels

* Update .github/scripts/release.test.js

Co-authored-by: Michael Paul <michael.paul@adyen.com>

---------

Co-authored-by: Michael Paul <michael.paul@adyen.com>
  • Loading branch information
AlexandrosMor and michaelpaul committed Sep 28, 2023
1 parent e9e798f commit b33df59
Show file tree
Hide file tree
Showing 2 changed files with 210 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/scripts/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ exports.detectChanges = (changeset) => {
break;
case 'breaking-change':
increment = 'major';
break;
return increment;
}
}
}
Expand Down
211 changes: 209 additions & 2 deletions .github/scripts/release.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,195 @@ const comparisonFixture = {
}
};

const associatedPullRequestsMajor = {
"repository": {
"name": "adyen-node-api-library",
"ref": {
"compare": {
"aheadBy": 8,
"commits": {
"edges": [
{
"node": {
"message": "Another commit in the same PR non squashed",
"associatedPullRequests": {
"edges": [
{
"node": {
"number": 20,
"labels": {
"nodes": [
{
"name": "Breaking change"
}
]
}
}
}
]
}
}
},
{
"node": {
"message": "Fixing the constructor",
"associatedPullRequests": {
"edges": [
{
"node": {
"number": 10,
"labels": {
"nodes": [
{
"name": "Fix"
}
]
}
}
}
]
}
}
},
{
"node": {
"message": "Upgrade some service",
"associatedPullRequests": {
"edges": [
{
"node": {
"number": 20,
"labels": {
"nodes": [
{
"name": "Feature"
}
]
}
}
}
]
}
}
},
{
"node": {
"message": "Update CODEOWNERS (#965)",
"associatedPullRequests": {
"edges": [
{
"node": {
"number": 30,
"labels": {
"nodes": []
}
}
}
]
}
}
}
]
}
}
}
}
};

const associatedPullRequestsMinor = {
"repository": {
"name": "adyen-node-api-library",
"ref": {
"compare": {
"aheadBy": 8,
"commits": {
"edges": [
{
"node": {
"message": "Another commit in the same PR non squashed",
"associatedPullRequests": {
"edges": [
{
"node": {
"number": 20,
"labels": {
"nodes": [
{
"name": ""
}
]
}
}
}
]
}
}
},
{
"node": {
"message": "Fixing the constructor",
"associatedPullRequests": {
"edges": [
{
"node": {
"number": 10,
"labels": {
"nodes": [
{
"name": "Feature"
}
]
}
}
}
]
}
}
},
{
"node": {
"message": "Upgrade some service",
"associatedPullRequests": {
"edges": [
{
"node": {
"number": 20,
"labels": {
"nodes": [
{
"name": "Fix"
}
]
}
}
}
]
}
}
},
{
"node": {
"message": "Update CODEOWNERS (#965)",
"associatedPullRequests": {
"edges": [
{
"node": {
"number": 30,
"labels": {
"nodes": []
}
}
}
]
}
}
}
]
}
}
}
}
};
beforeEach(() => {
// Reset env variables
delete process.env.CURRENT_VERSION;
Expand All @@ -134,7 +323,7 @@ test('Detect changes', async t => {

assert.strictEqual(ver, 'major');
});

await t.test('Zero changes', t => {
let sync = structuredClone(comparisonFixture);
sync.repository.ref.compare.aheadBy = 0;
Expand All @@ -158,6 +347,7 @@ test('Detect changes', async t => {
});
});


test('Get next version', async t => {
await t.test('Major', async t => {
const ver = release.nextVersion('13.1.2', 'major');
Expand Down Expand Up @@ -229,4 +419,21 @@ test('Bump', async t => {
await release.bump(options);

assert.strictEqual(core.setOutput.mock.calls.length, 3);
});
});


test('Calculate version major', async t => {
await t.test('Major', t => {
const ver = release.detectChanges(associatedPullRequestsMajor);

assert.strictEqual(ver, 'major');
})
});

test('Calculate version minor', async t => {
await t.test('Minor', t => {
const ver = release.detectChanges(associatedPullRequestsMinor);

assert.strictEqual(ver, 'minor');
});
});

0 comments on commit b33df59

Please sign in to comment.