Skip to content

Commit

Permalink
Merge pull request #3087 from snyk/feat/count-merge-commits
Browse files Browse the repository at this point in the history
Dev Count: count merge commits as well
  • Loading branch information
JackuB authored Apr 1, 2022
2 parents 69dc4b3 + b1be772 commit bbed47a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 40 deletions.
2 changes: 1 addition & 1 deletion src/lib/monitor/dev-count-analysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export async function runGitLog(
fnShellout: (cmd: string, workingDirectory: string) => Promise<string>,
): Promise<string> {
try {
const gitLogCommand = `git --no-pager log --no-merges --pretty=tformat:"%H${SERIOUS_DELIMITER}%an${SERIOUS_DELIMITER}%ae${SERIOUS_DELIMITER}%aI" --after="${timestampEpochSecondsStartOfPeriod}" --until="${timestampEpochSecondsEndOfPeriod}" --max-count=${MAX_COMMITS_IN_GIT_LOG}`;
const gitLogCommand = `git --no-pager log --pretty=tformat:"%H${SERIOUS_DELIMITER}%an${SERIOUS_DELIMITER}%ae${SERIOUS_DELIMITER}%aI" --after="${timestampEpochSecondsStartOfPeriod}" --until="${timestampEpochSecondsEndOfPeriod}" --max-count=${MAX_COMMITS_IN_GIT_LOG}`;
const gitLogStdout: string = await fnShellout(gitLogCommand, repoPath);
return gitLogStdout;
} catch {
Expand Down
41 changes: 2 additions & 39 deletions test/jest/unit/dev-count-analysis.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ const TIMESTAMP_TO_TEST = 1590174610000;

describe('cli dev count via git log analysis', () => {
let expectedContributoremails: string[] = [];
let expectedMergeOnlyemails: string[] = [];

// this computes the expectedContributoremails and expectedMergeOnlyemails
// this computes the expectedContributoremails
beforeAll(async () => {
const timestampEpochSecondsEndOfPeriod = Math.floor(
TIMESTAMP_TO_TEST / 1000,
Expand All @@ -42,24 +41,7 @@ describe('cli dev count via git log analysis', () => {
);
const uniqueEmails = [...new Set(allEmails)]; // dedupe the list of emails

const uniqueEmailsContainingOnlyMergeCommits: string[] = []; // a list of emails which are only associated with merge commits; don't include an email if it also have regular commits
const uniqueEmailsContainingAtLeastOneNonMergeCommit: string[] = [];
for (const nextEmail of uniqueEmails) {
const associatedCommits = withMergesLogLines.filter((l) =>
l.includes(nextEmail),
);
const allAssociatedCommitsAreMergeCommits = associatedCommits.every((e) =>
e.includes('Merge pull request'),
);
if (allAssociatedCommitsAreMergeCommits) {
uniqueEmailsContainingOnlyMergeCommits.push(nextEmail);
} else {
uniqueEmailsContainingAtLeastOneNonMergeCommit.push(nextEmail);
}
}

expectedContributoremails = uniqueEmailsContainingAtLeastOneNonMergeCommit;
expectedMergeOnlyemails = uniqueEmailsContainingOnlyMergeCommits;
expectedContributoremails = uniqueEmails;
}, testTimeout);

it(
Expand All @@ -78,25 +60,6 @@ describe('cli dev count via git log analysis', () => {
testTimeout,
);

it(
'does not include contributors who have only merged pull requests',
async () => {
const contributors = await getContributors({
endDate: new Date(TIMESTAMP_TO_TEST),
periodDays: 10,
repoPath: process.cwd(),
});
const contributoremails = contributors.map((c) => c.email);

// make sure none of uniqueEmailsContainingOnlyMergeCommits are in contributoremails
const legitemailsWhichAreAlsoInMergeOnlyemails = expectedMergeOnlyemails.filter(
(user) => contributoremails.includes(user),
);
expect(legitemailsWhichAreAlsoInMergeOnlyemails).toHaveLength(0);
},
testTimeout,
);

it('can calculate start of contributing developer period', () => {
const dEndMilliseconds = 1590174610000; // arbitrary timestamp in ms since epoch
const exectedStartTimestampSeconds = 1590174610 - 90 * 24 * 60 * 60;
Expand Down

0 comments on commit bbed47a

Please sign in to comment.