-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from tkskto/feature/add-branches
chore: add branch.
- Loading branch information
Showing
6 changed files
with
102 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,8 +13,9 @@ describe('authors test', () => { | |
]); | ||
} else { | ||
expect(authorData).toStrictEqual([ | ||
{name: 'kato takeshi', email: '[email protected]', commitCount: 1}, | ||
{name: 'tkskto', email: '[email protected]', commitCount: authorData[1].commitCount}, // TODO | ||
{name: 'Renovate Bot', email: '[email protected]', commitCount: authorData[0].commitCount}, | ||
{name: 'kato takeshi', email: '[email protected]', commitCount: authorData[1].commitCount}, | ||
{name: 'tkskto', email: '[email protected]', commitCount: authorData[2].commitCount}, | ||
]); | ||
} | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import {branches} from '../../src'; | ||
|
||
const isCI = process.argv[2] === '--ci'; | ||
|
||
describe('branch test', () => { | ||
test('local', async () => { | ||
const branch = await branches(false); | ||
|
||
if (isCI) { | ||
expect(branch.local.length).toStrictEqual(1); | ||
expect(branch.remote).toBeUndefined(); | ||
} else { | ||
expect(branch).toStrictEqual({ | ||
local: [ | ||
'feature/add-branches', | ||
'feature/add-remote-details', | ||
'main' | ||
], | ||
}); | ||
expect(branch.remote).toBeUndefined(); | ||
} | ||
}); | ||
|
||
test('remote', async () => { | ||
const branch = await branches(true); | ||
|
||
if (isCI) { | ||
expect(branch.local.length).toStrictEqual(1); | ||
if (branch.remote && branch.remote.pull) { | ||
expect(branch.remote.pull.length).toStrictEqual(1); | ||
} | ||
} else { | ||
expect(branch).toStrictEqual({ | ||
local: [ | ||
'feature/add-branches', | ||
'feature/add-remote-details', | ||
'main' | ||
], | ||
remote: { | ||
origin: [ 'feature/add-branches', 'main' ], | ||
}, | ||
}); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import {Branches} from 'git-log-nodejs'; | ||
import {getBranch} from './Execs'; | ||
import {makeErrorMessage} from './ErrorLogFactory'; | ||
|
||
export const branches = async (withRemote = true): Promise<Branches> => { | ||
try { | ||
const local: string = await getBranch(false); | ||
const lines: string[] = local.split(/\n|\r\n/g).map((name) => name.replace('* ', '').trim()); | ||
const result: Branches = { | ||
local: lines, | ||
}; | ||
|
||
if (withRemote) { | ||
const remote: string = await getBranch(true); | ||
const lines: string[] = remote.replace(local,'').split(/\n|\r\n/g); | ||
const remotes: Record<string, string[]> = {}; | ||
|
||
lines.forEach((branch: string) => { | ||
if (branch.includes('HEAD -> ')) { | ||
return; | ||
} | ||
|
||
const [remote, ...name] = branch.replace('remotes/', '').trim().split(/\//); | ||
|
||
if (!Object.prototype.hasOwnProperty.call(remotes, remote)) { | ||
remotes[remote] = []; | ||
} | ||
|
||
remotes[remote].push(name.join('/')); | ||
}); | ||
|
||
result.remote = remotes; | ||
} | ||
|
||
return result; | ||
} catch (err) { | ||
throw new Error(makeErrorMessage('authors in Author.ts', err.message)); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters