Skip to content

Commit

Permalink
fix(git): improve commit issue detection
Browse files Browse the repository at this point in the history
fixes is case insensitive now
  • Loading branch information
tagoro9 committed Jun 26, 2020
1 parent 36fa836 commit e245fe0
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/git/Git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ import {
map,
nthArg,
prop,
propEq,
props,
propSatisfies,
replace,
test,
trim,
uniqBy,
} from 'ramda';
Expand Down Expand Up @@ -265,7 +266,7 @@ export class Git {
issue: ref.issue,
raw: `${ref.prefix}${ref.issue}`,
})),
filter(propEq('action', 'fixes')),
filter(propSatisfies<string, CommitReference>(test(/fixes/i), 'action')),
prop('references') as (c: ParsedCommit) => CommitReference[],
),
),
Expand Down
31 changes: 31 additions & 0 deletions test/git/Git.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const gitMocks = {
},
}),
push: jest.fn().mockResolvedValue(undefined),
raw: jest.fn().mockResolvedValue(undefined),
revparse: jest.fn().mockResolvedValue(branchName),
stash: jest.fn().mockResolvedValue(undefined),
status: jest.fn().mockResolvedValue({
Expand Down Expand Up @@ -120,4 +121,34 @@ describe('Git', () => {
await expect(git.getRemote('origin')).rejects.toBeUndefined();
});
});

describe('getBranchInfo', () => {
it('should return the parsed commit history', async () => {
const baseCommit = {
author_email: 'test@fotingo.com',
author_name: 'Fotingo',
date: 'Fri Jun 26 08:09:23 2020 -0700',
};
const commits = [
{
...baseCommit,
hash: '570768fc6dee7d8983d323555146eb9529f0b701',
message: 'fix(something): fix this\n\nFixes #FOTINGO-123',
},
{
...baseCommit,
hash: 'bf4cf25bdfa6f9c9fffd6226a55071620b1e83a2',
message: 'feat(that): implement that\n\nfixes #FOTINGO-12',
},
{
...baseCommit,
hash: '3955a5ec9ed98ae53ebd49a70bed0a0523a08d61',
message: 'chore: improve this\n\nFixes #FOTINGO-1',
},
];
gitMocks.raw.mockResolvedValue(commits[0].hash);
gitMocks.log.mockResolvedValue({ all: commits });
await expect(git.getBranchInfo()).resolves.toMatchSnapshot();
});
});
});
92 changes: 92 additions & 0 deletions test/git/__snapshots__/Git.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,97 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Git getBranchInfo should return the parsed commit history 1`] = `
Object {
"commits": Array [
Object {
"body": null,
"footer": "Fixes #FOTINGO-123",
"header": "fix(something): fix this",
"mentions": Array [],
"merge": null,
"notes": Array [],
"references": Array [
Object {
"action": "Fixes",
"issue": "FOTINGO-123",
"owner": null,
"prefix": "#",
"raw": "#FOTINGO-123",
"repository": null,
},
],
"revert": null,
"scope": "something",
"subject": "fix this",
"type": "fix",
},
Object {
"body": null,
"footer": "fixes #FOTINGO-12",
"header": "feat(that): implement that",
"mentions": Array [],
"merge": null,
"notes": Array [],
"references": Array [
Object {
"action": "fixes",
"issue": "FOTINGO-12",
"owner": null,
"prefix": "#",
"raw": "#FOTINGO-12",
"repository": null,
},
],
"revert": null,
"scope": "that",
"subject": "implement that",
"type": "feat",
},
Object {
"body": null,
"footer": "Fixes #FOTINGO-1",
"header": "chore: improve this",
"mentions": Array [],
"merge": null,
"notes": Array [],
"references": Array [
Object {
"action": "Fixes",
"issue": "FOTINGO-1",
"owner": null,
"prefix": "#",
"raw": "#FOTINGO-1",
"repository": null,
},
],
"revert": null,
"scope": null,
"subject": "improve this",
"type": "chore",
},
],
"issues": Array [
Object {
"issue": "FOTINGO-493",
"raw": "#FOTINGO-493",
},
Object {
"issue": "FOTINGO-123",
"raw": "#FOTINGO-123",
},
Object {
"issue": "FOTINGO-12",
"raw": "#FOTINGO-12",
},
Object {
"issue": "FOTINGO-1",
"raw": "#FOTINGO-1",
},
],
"name": "FOTINGO-493",
}
`;

exports[`Git getBranchNameForIssue should generate a branch name for an issue 1`] = `"fotingo-2484"`;

exports[`Git getRemote should fall back to the first remote if it cannot find the specified one 1`] = `
Expand Down

0 comments on commit e245fe0

Please sign in to comment.