33import com .capitalone .dashboard .client .RestClient ;
44import com .capitalone .dashboard .client .RestUserInfo ;
55import com .capitalone .dashboard .misc .HygieiaException ;
6- import com .capitalone .dashboard .model .AuthorType ;
76import com .capitalone .dashboard .model .CollectionMode ;
87import com .capitalone .dashboard .model .Comment ;
98import 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 ("_" , "-" );
0 commit comments