-
Notifications
You must be signed in to change notification settings - Fork 147
fix: 946 associate commits by email #973
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
fix: 946 associate commits by email #973
Conversation
Git user.name may not be set to the GitHub username. GitHub uses the email address for lookup
✅ Deploy Preview for endearing-brigadeiros-63f9d0 canceled.
|
|
Looks like I didn't check the CLI test cases and need to sort something out there |
|
Fixed the failing tests but am waiting on a review (in git proxy), will update monday |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #973 +/- ##
==========================================
+ Coverage 81.28% 83.25% +1.97%
==========================================
Files 59 59
Lines 2458 2449 -9
Branches 279 280 +1
==========================================
+ Hits 1998 2039 +41
+ Misses 416 366 -50
Partials 44 44 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Code coverage is as good as I can get it, will pick up a little more when #979 is merged |
|
@JamieSlome @coopernetes @grovesy this is ready for a review. I think this will be important to supporting anything other than GitHub (alongside a fix for #950). |
|
@JamieSlome This is the PR we discussed expediting the review of - it'll be needed for supporting git repositories other than Github (work that is going well this week - but will generate another fairly large PR soon). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution! LGTM aside from the conflicts, may need additional approval before being merged.
|
@jescalada @coopernetes @06kellyjac I've maintained this against the recent merges to main and it should be ready to go again. One thing to note is that we're now doubling up on some of the tests, those in /test/testCheckUserPushPermission.test.js are integration tests, those in /test/processors/checkUserPushPermission.test.js are better unit tests (don't require data to be set up in the DB). However, I noted this latter set did NOT fail when there was an issue that was denying access to users that should have passed through. I've left both sets in place for now. |
|
Scratch that, there are still type errors that have lead me to some code in main that may not be correct in getMissingData where, the committer and author information is being confused:
I'd like to understand the use case for getMissingData - why do we need to pull the git log to get data that should be in the push? Why would Next, checking the push permissions for the authors and committer happens before that data is retrieved ( Finally, I've been meaning to mention that fact that we have duplicate types in multiple places, e.g.:
@jescalada @coopernetes @06kellyjac Can you let me know your thoughts and confirm whether the above was discussed in review or overlooked please. |
|
Looking closer at getMissingData I can see there is an attempt to validate a user has push permissions, but it is only the author of the last commit - I get that you don't see the committer in the git log - which is why I'm asking about the use case for that addition. Thats not the same as a check on committer (as per checkUserPushPermissions) nor is it ensuring that the all the authors were allowed (which we only check for 'legality' in checkAuthorEmails, right?, we don't require them all to have push perms). |
|
With getMissingData and the exception in checkUserPushPermissions, I suspect I could construct an artificial push with missing commitData, cherry-pick a commit from someone approved to push into the first (or possibly last) slot authored by an approved committer and pass the validation of pushPermissions, without actually having that permission. If thats the not the case, I'd love to se some comments added explaining. |
|
With getMissingData and the exception in checkUserPushPermissions, I suspect I could construct an artificial push with missing commitData, cherry-pick a commit from someone approved to push into the first (or possibly last) slot authored by an approved committer and pass the validation of pushPermissions, without actually having that permission. If thats the not the case, I'd love to see some comments added explaining. |
…ebase' into 946-associate-commits-by-email-rebase
|
@kriswest Thanks for letting me know about the
This was the PR description for the fix:
|
|
As for the
if (!user) {
console.log('Action has no user set. This may be due to a fast-forward ref update. Deferring to getMissingData action.');
return action;
}
return await validateUser(user, action, step);
if (action.commitData && action.commitData.length > 0) {
console.log('getMissingData', action);
return action;
}
if (await isEmptyBranch(action)) {
step.setError('Push blocked: Empty branch. Please make a commit before pushing a new branch.');
action.addStep(step);
step.error = true;
return action;
}
console.log(`commitData not found, fetching missing commits from git...`);
try {
const path = `${action.proxyGitPath}/${action.repoName}`;
const git = simpleGit(path);
const log = await git.log({ from: action.commitFrom, to: action.commitTo });
action.commitData = [...log.all].reverse().map((entry, i, array) => {
const parent = i === 0 ? action.commitFrom : array[i - 1].hash;
const timestamp = Math.floor(new Date(entry.date).getTime() / 1000).toString();
return {
message: entry.message || '',
committer: entry. || '',
tree: entry.hash || '',
parent: parent || EMPTY_COMMIT_HASH,
author: entry.author_name || '',
authorEmail: entry.author_email || '',
commitTimestamp: timestamp,
}
});
console.log(`Updated commitData:`, { commitData: action.commitData });
if (action.commitFrom === EMPTY_COMMIT_HASH) {
action.commitFrom = action.commitData[action.commitData.length - 1].parent;
}
const user = action.commitData[action.commitData.length - 1].committer;
action.user = user;
} catch (e: any) {
step.setError(e.toString('utf-8'));
} finally {
action.addStep(step);
}
return await validateUser(action.user || '', action, step); |
|
If you're referring to the issue with the A possible fix for this is to modify the const path = `${action.proxyGitPath}/${action.repoName}`;
const git = simpleGit(path);
const log = await git.log({
from: action.commitFrom,
to: action.commitTo,
format: {
hash: '%H',
date: '%ad',
message: '%s',
author_name: '%an',
author_email: '%ae',
tree: '%T',
parent: '%P',
committer: '%cn',
}
});
action.commitData = [...log.all].reverse().map((entry, i, array) => {
const parent = i === 0 ? action.commitFrom : array[i - 1].hash;
const timestamp = Math.floor(new Date(entry.date).getTime() / 1000).toString();
return {
message: entry.message || '',
committer: entry.committer || '',
tree: entry.hash || '',
parent: parent || EMPTY_COMMIT_HASH,
author: entry.author_name || '',
authorEmail: entry.author_email || '',
commitTimestamp: timestamp,
}
});There is another potential solution using |
|
I've looked at this in more detail: I don't recall 100%, but I'm pretty sure that the flow mentioned previously (making a new branch from an unapproved commit) was why I added the When reproducing this flow, I notice that @fabiovincenzi In other words, |
|
@jescalada thank you for looking into this. I wonder if we can create a test to investigate the issue, then leave it in place if I'm out of the office today, but will should be able to think more on it next week. I think the differentiation between authors and committers is important (to us as a large enterprise). We might have multiple authors contribute to a branch, then rely on a trusted committer and reviewer (who have fulfilled other policy requirements such as specified training or approval by leadership) to contribute that onwards to an external project. Hence, we'd be keen to make sure push are always tied to those doing the pushing, rather than the authors. Its is awkward that Finally, if P.S. I imagine other orgs might want to break out authors and govern those as well (beyond the 'legality' of their email address), but that's a conversation for another time ;-). |
|
@kriswest I've been doing manual testing with various kinds of merge commits and it seems the As for the empty branch check, I made a unit test that covers this in
|
|
@kriswest Just merged in the This will probably go into |
…ebase' into 946-associate-commits-by-email-rebase
|
np @jescalada, conflicts resolved and ready for one last look! I've had a go at resolving the conflicts between #973 and #1043 and have some commits lined up to resolve. I agree on the version numbering and can add the version number change to #1043 if desired. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Took a quick look at the code changes, and everything seems good to go!
resolves #946
Updates push parsing to extract commiter emails and to associate commits with users via email, rather than the git user.name config.
Note that:
https://docs.github.com/en/get-started/git-basics/setting-your-username-in-git
and
https://docs.github.com/en/account-and-profile/setting-up-and-managing-your-personal-account-on-github/managing-email-preferences/setting-your-commit-email-address