Skip to content

Commit

Permalink
fix: deal with the negative deterministic ext contrib check (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
gitcommitshow authored Oct 18, 2024
1 parent 9117036 commit eb2871e
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,11 @@ export function isExternalContributionMaybe(pullRequest) {
// NONE: Author has no association with the repository (or doesn't want to make his association public).
switch (pullRequest.author_association.toUpperCase()) {
case "OWNER":
pullRequest.isExternalContribution = false;
storage.cache.set(false, username, "contribution", "external", owner, repo);
return false;
case "MEMBER":
pullRequest.isExternalContribution = false;
storage.cache.set(false, username, "contribution", "external", owner, repo);
return false;
case "COLLABORATOR":
Expand All @@ -93,12 +95,18 @@ export function isExternalContributionMaybe(pullRequest) {
}
}
if (pullRequest?.head?.repo?.full_name !== pullRequest?.base?.repo?.full_name) {
pullRequest.isExternalContribution = true;
storage.cache.set(true, username, "contribution", "external", owner, repo);
return true;
} else if (pullRequest?.head?.repo?.full_name && pullRequest?.base?.repo?.full_name) {
pullRequest.isExternalContribution = false;
storage.cache.set(false, username, "contribution", "external", owner, repo);
return false;
}
// Utilize cache if possible
const isConfirmedToBeExternalContributionInPast = storage.cache.get(username, "contribution", "external", owner, repo);
if (typeof isConfirmedToBeExternalContributionInPast === "boolean") {
pullRequest.isExternalContribution = isConfirmedToBeExternalContributionInPast;
return isConfirmedToBeExternalContributionInPast
}
// Ambigous results after this point.
Expand Down Expand Up @@ -521,7 +529,7 @@ async function isAllowedToWriteToTheRepo(octokit, username, owner, repo,) {
// The app is not installed in that repo
// Only "metadata:repository" permission is needed for this api, which all gh apps have wherever they are installed
console.log("Failed to check if a " + username + " is allowed to write to " + owner + "/" + repo);
console.error(err);
// console.error(err);
throw new Error("Failed to check user permission for the repo")
}
}
Expand Down

0 comments on commit eb2871e

Please sign in to comment.