Skip to content
This repository has been archived by the owner on Oct 2, 2023. It is now read-only.

Commit

Permalink
fallback to use authorLogin for decisioning (#248)
Browse files Browse the repository at this point in the history
* fallback to use authorLogin for decisioning

* remove the optimization for UserType
  • Loading branch information
rvema authored Oct 20, 2021
1 parent 5d345e6 commit 0210f06
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 14 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<artifactId>api</artifactId>
<packaging>jar</packaging>
<name>${project.groupId}:${project.artifactId}</name>
<version>3.4.26</version>
<version>3.4.27</version>
<description>Hygieia Rest API Layer</description>
<url>https://github.com/Hygieia/api</url>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ protected List<Commit> getCommits(List<Map> commitListPayload, String repoUrl,
String authorLDAPDN = restClient.getString(senderObj, "ldap_dn");
if (!StringUtils.isEmpty(authorLDAPDN)) {
commit.setScmAuthorLDAPDN(authorLDAPDN);
} else {
commit.setScmAuthorLDAPDN(getLDAPDN(repoUrl, authorLogin, gitHubWebHookToken));
}
} else {
long start = System.currentTimeMillis();
Expand All @@ -206,7 +208,7 @@ protected List<Commit> getCommits(List<Map> commitListPayload, String repoUrl,
}
// if ldap dn is null set it from ldapMap
if(StringUtils.isEmpty(commit.getScmAuthorLDAPDN())){
commit.setScmAuthorLDAPDN(getLDAPDN(repoUrl, StringUtils.isEmpty(scmAuthorName) ? authorLogin : scmAuthorName, gitHubWebHookToken));
commit.setScmAuthorLDAPDN(getLDAPDN(repoUrl, authorLogin, gitHubWebHookToken));
}
// Set the Committer details. This in the case of a merge commit is the user who merges the PR.
// In the case of a regular commit, it is usually set to a default "name": "GitHub Enterprise", and login is null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ protected List<Commit> getPRCommits(String repoUrl, Object commitsObject, GitReq
if (!StringUtils.isEmpty(authorType)) {
newCommit.setScmAuthorType(authorType);
}
String authorLDAPDN = getLDAPDN(repoUrl, StringUtils.isEmpty(scmAuthorName) ? newCommit.getScmAuthorLogin() : scmAuthorName, token);
String authorLDAPDN = getLDAPDN(repoUrl, newCommit.getScmAuthorLogin(), token);
if (!StringUtils.isEmpty(authorLDAPDN)) {
newCommit.setScmAuthorLDAPDN(authorLDAPDN);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,16 +190,6 @@ protected void getUser(String repoUrl, String user, String token) {
String formattedUser = user.replace("_", "-");
int retryCount = 0;
ResponseEntity<String> response;

if(apiSettings.isOptimizeUserCallsToGithub()) {
UserEntitlements entitlements = userEntitlementsRepository.findTopByAuthTypeAndEntitlementTypeAndUsername(AuthType.LDAP,
ENTITLEMENT_TYPE, StringUtils.lowerCase(user));
String ldapDN = (entitlements == null) ? "" : entitlements.getEntitlements();
ldapMap.put(user, ldapDN);
authorTypeMap.put(user, "User");
return;
}

while(true) {
try {
long start = System.currentTimeMillis();
Expand Down Expand Up @@ -239,7 +229,9 @@ protected String getLDAPDN(String repoUrl, String user, String token) {
if (ldapMap == null) { ldapMap = new HashMap<>(); }

if(apiSettings.isOptimizeUserCallsToGithub()) {
return ldapMap.get(user);
UserEntitlements entitlements = userEntitlementsRepository.findTopByAuthTypeAndEntitlementTypeAndUsername(AuthType.LDAP,
ENTITLEMENT_TYPE, StringUtils.lowerCase(user));
return (entitlements == null) ? "" : entitlements.getEntitlements();
}

//This is weird. Github does replace the _ in commit author with - in the user api!!!
Expand Down

0 comments on commit 0210f06

Please sign in to comment.