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

chore: attach labels to release, update CI #102

Merged
merged 8 commits into from
Aug 2, 2023
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
7 changes: 4 additions & 3 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,20 @@ jobs:
npm run test:cov
- name: Report coverage
if: always()
uses: slavcodev/coverage-monitor-action@1.1.0
uses: slavcodev/coverage-monitor-action@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
clover_file: coverage/clover.xml
coverage_path: coverage/clover.xml
threshold_alert: 50
threshold_warning: 75
comment_mode: update
- name: Save Code Linting Report JSON
if: always()
run: npm run lint:report
continue-on-error: true
- name: Annotate Code Linting Results
if: always()
uses: ataylorme/eslint-annotate-action@1.0.4
uses: ataylorme/eslint-annotate-action@v2
with:
repo-token: '${{ secrets.GITHUB_TOKEN }}'
report-json: 'eslint_report.json'
22 changes: 21 additions & 1 deletion src/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,26 @@ export default function githubFactory(token, repository) {
});
});
},
/**
* Create the release pull request
* @param {String} repo - owner and name of the repository
* @param {Number} number - issue number
* @param {String[]} label - label name
* @returns {Promise<Object>} - resolves with the add label data, if the label is added
*/
addLabel(repo, number, label) {
const ghpr = client.issue(repo, number);
return new Promise((resolve, reject) => {
ghpr.addLabels({
labels: label
}, (err, data) => {
if (err) {
return reject(err);
}
return resolve(data);
});
});
},

/**
* Create the release pull request
Expand Down Expand Up @@ -341,4 +361,4 @@ export default function githubFactory(token, repository) {
.reduce((acc, note) => note ? `${acc} - ${note}\n` : acc, '');
}
};
}
}
21 changes: 11 additions & 10 deletions src/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import configFactory from './config.js';
import github from './github.js';
import gitClientFactory from './git.js';
import log from './log.js';
import conventionalCommits from './conventionalCommits.js';
import conventionalCommits from './conventionalCommits.js';
import semverValid from 'semver/functions/valid.js';

import extension from './release/extensionApi.js';
Expand Down Expand Up @@ -233,17 +233,18 @@ export default function taoExtensionReleaseFactory(params = {}) {
releaseBranch,
data.version,
data.lastVersion,
subjectType
subjectType,
);

if (pullRequest && pullRequest.state === 'open') {
data.pr = {
url: pullRequest.html_url,
apiUrl: pullRequest.url,
number: pullRequest.number,
id: pullRequest.id
id: pullRequest.id,
full_name: pullRequest.head.repo.full_name,
};

const labels = ['releases'];
await githubClient.addLabel(data.pr.full_name, data.pr.number, labels);
log.info(`${data.pr.url} created`);
log.done();
} else {
Expand Down Expand Up @@ -614,18 +615,18 @@ export default function taoExtensionReleaseFactory(params = {}) {
} = await conventionalCommits.getNextVersion(lastTag);

if (releaseVersion) {
if(!semverGt(releaseVersion, lastVersion)) {
if (!semverGt(releaseVersion, lastVersion)) {
log.exit(`The provided version is lesser than the latest version ${lastVersion}.`);
}
log.info(`Release version provided: ${releaseVersion}`);
} else {

if (interactive) {
if (recommendation.stats && recommendation.stats.commits === 0) {
const { releaseAgain } = await inquirer.prompt({
const { releaseAgain } = await inquirer.prompt({
type: 'confirm',
name: 'releaseAgain',
default : false,
default: false,
message: 'There\'s no new commits, do you really want to release a new version?'
});

Expand All @@ -634,7 +635,7 @@ export default function taoExtensionReleaseFactory(params = {}) {
}
}
else if (recommendation.stats && recommendation.stats.unset > 0) {
const { acceptDefaultVersion } = await inquirer.prompt({
const { acceptDefaultVersion } = await inquirer.prompt({
type: 'confirm',
name: 'acceptDefaultVersion',
message: recommendation.stats.unset === recommendation.stats.commits ?
Expand Down Expand Up @@ -686,4 +687,4 @@ export default function taoExtensionReleaseFactory(params = {}) {
await gitClient.commitAndPush(data.releasingBranch, 'chore: bump version');
}
};
}
}
58 changes: 43 additions & 15 deletions tests/unit/release/createPullRequest/release.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ jest.mock('../../../../src/github.js', () => {
...originalModule,
default: jest.fn(() => ({
createReleasePR: jest.fn(),
addLabel: jest.fn(() => { }),
release: jest.fn(),
extractReleaseNotesFromReleasePR: jest.fn()
}))
Expand Down Expand Up @@ -67,7 +68,7 @@ afterAll(() => {
});

describe('src/release.js createPullRequest', () => {

test('should define createPullRequest method on release instance', () => {
expect.assertions(1);

Expand Down Expand Up @@ -100,17 +101,26 @@ describe('src/release.js createPullRequest', () => {
expect.assertions(2);

const url = 'testUrl';

const release = releaseFactory({ branchPrefix, releaseBranch });
jest.spyOn(release, 'getMetadata').mockImplementationOnce(() => ({ repoName }));
const createReleasePR = jest.fn(() => ({
state: 'open',
html_url: url,
url: 'apiUrl',
number: 42,
id: 'pr_id',
head: {
repo: {
full_name: 'fullName'
}
}
}));
const addLabel = jest.fn();
github.mockImplementationOnce(() => {
//Mock the default export
return {
createReleasePR
createReleasePR,
addLabel
};
});

Expand All @@ -125,29 +135,36 @@ describe('src/release.js createPullRequest', () => {
test('should set data.pr', async () => {
expect.assertions(1);

const html_url = 'testUrl';
const apiUrl = 'apiUrl';
const html_url = 'apiUrl';
const number = 42;
const id = 'pr_id';
const expectedPR = {
url: html_url,
apiUrl,
number,
id
url: 'apiUrl',
apiUrl: 'apiUrl',
number: 42,
id: 'pr_id',
full_name: 'fullName'
};
const release = releaseFactory({ branchPrefix, releaseBranch });
jest.spyOn(release, 'getMetadata').mockImplementationOnce(() => ({ repoName }));
const createReleasePR = jest.fn(() => ({
state: 'open',
html_url,
url: apiUrl,
html_url: html_url,
url: html_url,
number,
id
id,
head: {
repo: {
full_name: 'fullName'
}
}
}));
const addLabel = jest.fn();
github.mockImplementationOnce(() => {
//Mock the default export
return {
createReleasePR
createReleasePR,
addLabel
};
});

Expand All @@ -165,11 +182,22 @@ describe('src/release.js createPullRequest', () => {
jest.spyOn(release, 'getMetadata').mockImplementationOnce(() => ({ repoName }));
const createReleasePR = jest.fn(() => ({
state: 'open',
html_url: 'apiUrl',
url: 'apiUrl',
number: 42,
id: 'pr_id',
head: {
repo: {
full_name: 'fullName'
}
}
}));
const addLabel = jest.fn();
github.mockImplementationOnce(() => {
//Mock the default export
return {
createReleasePR
createReleasePR,
addLabel
};
});

Expand All @@ -193,4 +221,4 @@ describe('src/release.js createPullRequest', () => {
expect(log.exit).toBeCalledTimes(1);
expect(log.exit).toBeCalledWith('Unable to create the release pull request');
});
});
});
32 changes: 22 additions & 10 deletions tests/unit/release/mergePullRequest/release.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,19 @@ jest.mock('../../../../src/github.js', () => {
__esModule: true,
...originalModule,
default: jest.fn(() => ({
createReleasePR: jest.fn(() => ({ state: 'open' })),
createReleasePR: jest.fn(() => ({
state: 'open',
html_url: 'apiUrl',
url: 'apiUrl',
number: 42,
id: 'pr_id',
head: {
repo: {
full_name: 'fullName'
}
}
})),
addLabel: jest.fn(() => { }),
release: jest.fn(),
extractReleaseNotesFromReleasePR: jest.fn()
}))
Expand All @@ -71,13 +83,13 @@ jest.mock('../../../../src/git.js', () => {
__esModule: true,
...originalModule,
default: jest.fn(() => ({
tag: jest.fn(arg => arg),
localBranch: jest.fn(arg => arg),
push: jest.fn(arg => arg),
hasBranch: jest.fn(),
tag: jest.fn(arg => arg),
localBranch: jest.fn(arg => arg),
push: jest.fn(arg => arg),
hasBranch: jest.fn(),
hasTag: jest.fn(),
getLastTag: jest.fn(),
hasDiff: jest.fn(() => true),
hasDiff: jest.fn(() => true),
mergeBack: jest.fn(),
pull: jest.fn(),
merge: jest.fn(),
Expand Down Expand Up @@ -118,15 +130,15 @@ describe('src/release.js mergePullRequest', () => {
jest.clearAllMocks();
jest.useRealTimers();
});

test('should define mergePullRequest method on release instance', () => {
expect.assertions(1);

const release = releaseFactory({ baseBranch, releaseBranch });
release.setData({ releasingBranch, token, extension: {} });
expect(typeof release.mergePullRequest).toBe('function');
});

test('should open pull request in browser', async () => {
expect.assertions(1);

Expand Down Expand Up @@ -223,4 +235,4 @@ describe('src/release.js mergePullRequest', () => {
expect(log.done).toBeCalledTimes(2);
expect(log.done).toBeCalledWith('PR merged');
});
});
});
Loading