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(ci): parse commits correctly #294

Merged
merged 3 commits into from
Mar 25, 2022
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
30 changes: 15 additions & 15 deletions scripts/release/__tests__/create-release-issue.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@ describe('create release issue', () => {
});

it('parses commit', () => {
expect(parseCommit(`abcdefg fix(javascript): fix the thing`)).toEqual({
hash: 'abcdefg',
expect(parseCommit(`b2501882 fix(javascript): fix the thing`)).toEqual({
hash: 'b2501882',
lang: 'javascript',
message: 'fix the thing',
raw: 'abcdefg fix(javascript): fix the thing',
raw: 'b2501882 fix(javascript): fix the thing',
type: 'fix',
});
});

it('returns error when language scope is missing', () => {
expect(parseCommit(`abcdefg fix: fix the thing`)).toEqual({
expect(parseCommit(`b2501882 fix: fix the thing`)).toEqual({
error: 'missing-language-scope',
});
});

it('returns error when language scope is unknown', () => {
expect(parseCommit(`abcdefg fix(basic): fix the thing`)).toEqual({
expect(parseCommit(`b2501882 fix(basic): fix the thing`)).toEqual({
error: 'unknown-language-scope',
});
});
Expand Down Expand Up @@ -125,11 +125,11 @@ describe('create release issue', () => {
},
commits: [
{
hash: 'abcdefg',
hash: 'b2501882',
type: 'feat',
lang: 'javascript',
message: 'update the API (BREAKING CHANGE)',
raw: 'abcdefg feat(javascript): update the API (BREAKING CHANGE)',
raw: 'b2501882 feat(javascript): update the API (BREAKING CHANGE)',
},
],
});
Expand All @@ -152,11 +152,11 @@ describe('create release issue', () => {
},
commits: [
{
hash: 'abcdefg',
hash: 'b2501882',
type: 'feat',
lang: 'php',
message: 'update the API',
raw: 'abcdefg feat(php): update the API',
raw: 'b2501882 feat(php): update the API',
},
],
});
Expand All @@ -179,11 +179,11 @@ describe('create release issue', () => {
},
commits: [
{
hash: 'abcdefg',
hash: 'b2501882',
type: 'fix',
lang: 'java',
message: 'fix some bug',
raw: 'abcdefg fix(java): fix some bug',
raw: 'b2501882 fix(java): fix some bug',
},
],
});
Expand All @@ -206,11 +206,11 @@ describe('create release issue', () => {
},
commits: [
{
hash: 'abcdefg',
hash: 'b2501882',
type: 'fix',
lang: 'java',
message: 'fix some bug',
raw: 'abcdefg fix(java): fix some bug',
raw: 'b2501882 fix(java): fix some bug',
},
],
});
Expand All @@ -235,11 +235,11 @@ describe('create release issue', () => {
},
commits: [
{
hash: 'abcdefg',
hash: 'b2501882',
type: 'chore',
lang: 'javascript',
message: 'update devDevpendencies',
raw: 'abcdefg chore(javascript): update devDevpendencies',
raw: 'b2501882 chore(javascript): update devDevpendencies',
},
],
});
Expand Down
5 changes: 3 additions & 2 deletions scripts/release/create-release-issue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ export function getVersionChangesText(versions: Versions): string {
}

export function parseCommit(commit: string): Commit {
const hash = commit.slice(0, 7);
let message = commit.slice(8);
const LENGTH_SHA1 = 8;
const hash = commit.slice(0, LENGTH_SHA1);
let message = commit.slice(LENGTH_SHA1 + 1);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the code just below, the CI allows empty scope for chores and docs, it will trigger the error line 68 I think.
Either we always enforce scope or you check here for the type first.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, but chore and docs commit don't affect versioning. So it's okay to ignore them. It returns { error: '...' } but later the script just prints out the warning messages. (We are planning to include these ignored commits within the release issue in a separate PR)

What do you think?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh sorry I didn't see the rest of the code, all good then

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries. Thanks for the comment!

let type = message.slice(0, message.indexOf(':'));
const matchResult = type.match(/(.+)\((.+)\)/);
if (!matchResult) {
Expand Down