@@ -3,6 +3,10 @@ import { resolve } from "path";
33import { PROJECT_ROOT_PATH } from "./config.js" ;
44import url from "node:url" ;
55
6+ function isOneCLAPerOrgEnough ( ) {
7+ return process . env . ONE_CLA_PER_ORG ?. toLowerCase ( ) ?. trim ( ) === "true" ? true : false ;
8+ }
9+
610export function parseUrlQueryParams ( urlString ) {
711 if ( ! urlString ) return urlString ;
812 try {
@@ -79,15 +83,15 @@ export function isExternalContributionMaybe(pullRequest) {
7983 switch ( pullRequest . author_association . toUpperCase ( ) ) {
8084 case "OWNER" :
8185 pullRequest . isExternalContribution = false ;
82- storage . cache . set ( false , username , "contribution" , "external" , owner , repo ) ;
86+ storage . cache . set ( false , username , "contribution" , "external" , owner , isOneCLAPerOrgEnough ( ) ? undefined : repo ) ;
8387 return false ;
8488 case "MEMBER" :
8589 pullRequest . isExternalContribution = false ;
86- storage . cache . set ( false , username , "contribution" , "external" , owner , repo ) ;
90+ storage . cache . set ( false , username , "contribution" , "external" , owner , isOneCLAPerOrgEnough ( ) ? undefined : repo ) ;
8791 return false ;
8892 case "COLLABORATOR" :
8993 pullRequest . isExternalContribution = false ;
90- storage . cache . set ( false , username , "contribution" , "external" , owner , repo ) ;
94+ storage . cache . set ( false , username , "contribution" , "external" , owner , isOneCLAPerOrgEnough ( ) ? undefined : repo ) ;
9195 return false ;
9296 default :
9397 //Will need more checks to verify author relation with the repo
@@ -96,15 +100,15 @@ export function isExternalContributionMaybe(pullRequest) {
96100 }
97101 if ( pullRequest ?. head ?. repo ?. full_name !== pullRequest ?. base ?. repo ?. full_name ) {
98102 pullRequest . isExternalContribution = true ;
99- storage . cache . set ( true , username , "contribution" , "external" , owner , repo ) ;
103+ storage . cache . set ( true , username , "contribution" , "external" , owner , isOneCLAPerOrgEnough ( ) ? undefined : repo ) ;
100104 return true ;
101105 } else if ( pullRequest ?. head ?. repo ?. full_name && pullRequest ?. base ?. repo ?. full_name ) {
102106 pullRequest . isExternalContribution = false ;
103- storage . cache . set ( false , username , "contribution" , "external" , owner , repo ) ;
107+ storage . cache . set ( false , username , "contribution" , "external" , owner , isOneCLAPerOrgEnough ( ) ? undefined : repo ) ;
104108 return false ;
105109 }
106110 // Utilize cache if possible
107- const isConfirmedToBeExternalContributionInPast = storage . cache . get ( username , "contribution" , "external" , owner , repo ) ;
111+ const isConfirmedToBeExternalContributionInPast = storage . cache . get ( username , "contribution" , "external" , owner , isOneCLAPerOrgEnough ( ) ? undefined : repo ) ;
108112 if ( typeof isConfirmedToBeExternalContributionInPast === "boolean" ) {
109113 pullRequest . isExternalContribution = isConfirmedToBeExternalContributionInPast ;
110114 return isConfirmedToBeExternalContributionInPast
@@ -126,7 +130,7 @@ async function isExternalContribution(octokit, pullRequest) {
126130 //TODO: Handle failure in checking permissions for the user
127131 const deterministicPermissionCheck = await isAllowedToWriteToTheRepo ( octokit , username , owner , repo ) ;
128132 pullRequest . isExternalContribution = deterministicPermissionCheck ;
129- storage . cache . set ( deterministicPermissionCheck , username , "contribution" , "external" , owner , repo ) ;
133+ storage . cache . set ( deterministicPermissionCheck , username , "contribution" , "external" , owner , isOneCLAPerOrgEnough ( ) ? undefined : repo ) ;
130134 return deterministicPermissionCheck ;
131135}
132136
0 commit comments