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

Commit a09dde0

Browse files
authored
Change authorType from enum to string (#38)
* Change authorType from enum to string * Fix an error in pom file
1 parent b1928ca commit a09dde0

3 files changed

Lines changed: 50 additions & 21 deletions

File tree

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
</description>
99
<url>https://github.com/Hygieia/${repository.name}</url>
1010
<packaging>jar</packaging>
11-
<version>3.1.3-SNAPSHOT</version>
11+
<version>3.1.4-SNAPSHOT</version>
1212

1313
<parent>
1414
<groupId>com.capitalone.dashboard</groupId>
@@ -50,7 +50,7 @@
5050
<repository.name>hygieia-scm-github-graphql-collector</repository.name>
5151
<apache.rat.plugin.version>0.13</apache.rat.plugin.version>
5252
<bc.version>3.0.1</bc.version>
53-
<com.capitalone.dashboard.core.version>3.7.9</com.capitalone.dashboard.core.version>
53+
<com.capitalone.dashboard.core.version>3.7.11</com.capitalone.dashboard.core.version>
5454
<commons.io.version>2.4</commons.io.version>
5555
<commons.lang.version>3.8.1</commons.lang.version>
5656
<coveralls.maven.plugin.version>4.3.0</coveralls.maven.plugin.version>

src/main/java/com/capitalone/dashboard/collector/DefaultGitHubClient.java

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import com.capitalone.dashboard.client.RestClient;
44
import com.capitalone.dashboard.client.RestUserInfo;
55
import com.capitalone.dashboard.misc.HygieiaException;
6-
import com.capitalone.dashboard.model.AuthorType;
76
import com.capitalone.dashboard.model.CollectionMode;
87
import com.capitalone.dashboard.model.Comment;
98
import com.capitalone.dashboard.model.Commit;
@@ -72,7 +71,7 @@ public class DefaultGitHubClient implements GitHubClient {
7271
private List<GitRequest> pullRequests;
7372
private List<GitRequest> issues;
7473
private Map<String, String> ldapMap;
75-
private Map<String, AuthorType> authorTypeMap;
74+
private Map<String, String> authorTypeMap;
7675
private final List<Pattern> commitExclusionPatterns = new ArrayList<>();
7776

7877

@@ -139,9 +138,9 @@ protected Map<String, String> getLdapMap() {
139138
return ldapMap;
140139
}
141140

142-
protected void setAuthorTypeMap(Map<String, AuthorType> authorTypeMap) { this.authorTypeMap = authorTypeMap; }
141+
protected void setAuthorTypeMap(Map<String, String > authorTypeMap) { this.authorTypeMap = authorTypeMap; }
143142

144-
protected Map<String, AuthorType> getAuthorTypeMap() { return authorTypeMap; }
143+
protected Map<String, String> getAuthorTypeMap() { return authorTypeMap; }
145144

146145
@Override
147146
@SuppressWarnings("PMD.ExcessiveMethodLength")
@@ -558,8 +557,14 @@ private GitHubPaging processPullRequest(JSONObject pullObject, GitHubRepo repo,
558557
if (mergeEvent != null) {
559558
pull.setScmMergeEventRevisionNumber(mergeEvent.getMergeSha());
560559
pull.setMergeAuthor(mergeEvent.getMergeAuthor());
561-
pull.setMergeAuthorLDAPDN(getLDAPDN(repo, pull.getMergeAuthor()));
562-
pull.setMergeAuthorType(getAuthorType(repo, pull.getMergeAuthor()));
560+
String authorType = getAuthorType(repo, pull.getMergeAuthor());
561+
String authorLDAPDN = getLDAPDN(repo, pull.getMergeAuthor());
562+
if (StringUtils.isNotEmpty(authorType)) {
563+
pull.setMergeAuthorType(authorType);
564+
}
565+
if (StringUtils.isNotEmpty(authorLDAPDN)) {
566+
pull.setMergeAuthorLDAPDN(authorLDAPDN);
567+
}
563568
}
564569
}
565570
// commit etc details
@@ -753,8 +758,14 @@ private List<Comment> getComments(GitHubRepo repo, JSONObject commentsJSON) thro
753758
Comment comment = new Comment();
754759
comment.setBody(str(node, "bodyText"));
755760
comment.setUser(str((JSONObject) node.get("author"), "login"));
756-
comment.setUserType(getAuthorType(repo, comment.getUser()));
757-
comment.setUserLDAPDN(getLDAPDN(repo, comment.getUser()));
761+
String userType = getAuthorType(repo, comment.getUser());
762+
String userLDAPDN = getLDAPDN(repo, comment.getUser());
763+
if (StringUtils.isNotEmpty(userType)) {
764+
comment.setUserType(userType);
765+
}
766+
if (StringUtils.isNotEmpty(userLDAPDN)) {
767+
comment.setUserLDAPDN(userLDAPDN);
768+
}
758769
comment.setCreatedAt(getTimeStampMills(str(node, "createdAt")));
759770
comment.setUpdatedAt(getTimeStampMills(str(node, "updatedAt")));
760771
comment.setStatus(str(node, "state"));
@@ -787,8 +798,14 @@ private List<Commit> getPRCommits(GitHubRepo repo, JSONObject commits, GitReques
787798
JSONObject authorUserJSON = (JSONObject) author.get("user");
788799
newCommit.setScmAuthor(str(author, "name"));
789800
newCommit.setScmAuthorLogin(authorUserJSON == null ? "unknown" : str(authorUserJSON, "login"));
790-
newCommit.setScmAuthorType(getAuthorType(repo, newCommit.getScmAuthorLogin()));
791-
newCommit.setScmAuthorLDAPDN(getLDAPDN(repo, newCommit.getScmAuthorLogin()));
801+
String authorType = getAuthorType(repo, newCommit.getScmAuthorLogin());
802+
String authorLDAPDN = getLDAPDN(repo, newCommit.getScmAuthorLogin());
803+
if (StringUtils.isNotEmpty(authorType)) {
804+
newCommit.setScmAuthorType(authorType);
805+
}
806+
if (StringUtils.isNotEmpty(authorLDAPDN)) {
807+
newCommit.setScmAuthorLDAPDN(authorLDAPDN);
808+
}
792809
newCommit.setScmCommitTimestamp(getTimeStampMills(str(author, "date")));
793810
JSONObject statusObj = (JSONObject) commit.get("status");
794811

@@ -868,8 +885,14 @@ private List<Review> getReviews(GitHubRepo repo, JSONObject reviewObject) throws
868885
review.setBody(str(node, "bodyText"));
869886
JSONObject authorObj = (JSONObject) node.get("author");
870887
review.setAuthor(str(authorObj, "login"));
871-
review.setAuthorType(getAuthorType(repo, review.getAuthor()));
872-
review.setAuthorLDAPDN(getLDAPDN(repo, review.getAuthor()));
888+
String authorType = getAuthorType(repo, review.getAuthor());
889+
String authorLDAPDN = getLDAPDN(repo, review.getAuthor());
890+
if (StringUtils.isNotEmpty(authorType)) {
891+
review.setAuthorType(authorType);
892+
}
893+
if (StringUtils.isNotEmpty(authorLDAPDN)) {
894+
review.setAuthorLDAPDN(authorLDAPDN);
895+
}
873896
review.setCreatedAt(getTimeStampMills(str(node, "createdAt")));
874897
review.setUpdatedAt(getTimeStampMills(str(node, "updatedAt")));
875898
reviews.add(review);
@@ -901,8 +924,14 @@ private MergeEvent getMergeEvent(GitHubRepo repo, GitRequest pr, JSONObject time
901924
JSONObject author = (JSONObject) node.get("actor");
902925
if (author != null) {
903926
mergeEvent.setMergeAuthor(str(author, "login"));
904-
mergeEvent.setMergeAuthorType(getAuthorType(repo, mergeEvent.getMergeAuthor()));
905-
mergeEvent.setMergeAuthorLDAPDN(getLDAPDN(repo, mergeEvent.getMergeAuthor()));
927+
String authorType = getAuthorType(repo, mergeEvent.getMergeAuthor());
928+
String authorLDAPDN = getLDAPDN(repo, mergeEvent.getMergeAuthor());
929+
if (StringUtils.isNotEmpty(authorType)) {
930+
mergeEvent.setMergeAuthorType(authorType);
931+
}
932+
if (StringUtils.isNotEmpty(authorLDAPDN)) {
933+
mergeEvent.setMergeAuthorLDAPDN(authorLDAPDN);
934+
}
906935
}
907936
return mergeEvent;
908937
}
@@ -1004,7 +1033,7 @@ private void getUser(GitHubRepo repo, String user) {
10041033
ldapMap.put(user, ldapDN);
10051034
}
10061035
if (StringUtils.isNotEmpty(authorTypeStr)) {
1007-
authorTypeMap.put(user, AuthorType.fromString(authorTypeStr));
1036+
authorTypeMap.put(user, authorTypeStr);
10081037
}
10091038
} catch (MalformedURLException | HygieiaException | RestClientException e) {
10101039
LOG.error("Error getting LDAP_DN For user " + user, e);
@@ -1023,7 +1052,7 @@ public String getLDAPDN(GitHubRepo repo, String user) {
10231052
return ldapMap.get(formattedUser);
10241053
}
10251054

1026-
private AuthorType getAuthorType(GitHubRepo repo, String user) {
1055+
private String getAuthorType(GitHubRepo repo, String user) {
10271056
if (StringUtils.isEmpty(user) || "unknown".equalsIgnoreCase(user)) return null;
10281057
//This is weird. Github does replace the _ in commit author with - in the user api!!!
10291058
String formattedUser = user.replace("_", "-");

src/main/java/com/capitalone/dashboard/model/MergeEvent.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ public class MergeEvent {
55
private String gitRequestNumber;
66
private String mergeRef;
77
private String mergeAuthor;
8-
private AuthorType mergeAuthorType;
8+
private String mergeAuthorType;
99
private String mergeAuthorLDAPDN;
1010
private long mergedAt;
1111

@@ -41,9 +41,9 @@ public void setMergeAuthor(String mergeAuthor) {
4141
this.mergeAuthor = mergeAuthor;
4242
}
4343

44-
public AuthorType getMergeAuthorType() { return mergeAuthorType; }
44+
public String getMergeAuthorType() { return mergeAuthorType; }
4545

46-
public void setMergeAuthorType(AuthorType mergeAuthorType) { this.mergeAuthorType = mergeAuthorType; }
46+
public void setMergeAuthorType(String mergeAuthorType) { this.mergeAuthorType = mergeAuthorType; }
4747

4848
public String getMergeAuthorLDAPDN() {
4949
return mergeAuthorLDAPDN;

0 commit comments

Comments
 (0)