@Override
    public List<Commit> getCommits(GitHubRepo repo, boolean firstRun, List<Pattern> commitExclusionPatterns) throws RestClientException, MalformedURLException, HygieiaException {

        List<Commit> commits = new ArrayList<>();

        // format URL
        String repoUrl = (String) repo.getOptions().get("url");
        GitHubParsed gitHubParsed = new GitHubParsed(repoUrl);
        String apiUrl = gitHubParsed.getApiUrl();

        String queryUrl = apiUrl.concat("/commits?sha=" + repo.getBranch()
                + "&since=" + getTimeForApi(getRunDate(repo, firstRun)));
        String decryptedPassword = decryptString(repo.getPassword(), settings.getKey());
        String personalAccessToken = (String) repo.getOptions().get("personalAccessToken");
        String decryptedPersonalAccessToken = decryptString(personalAccessToken, settings.getKey());
        boolean lastPage = false;
        String queryUrlPage = queryUrl;
        while (!lastPage) {
            LOG.info("Executing " + queryUrlPage);
            ResponseEntity<String> response = makeRestCall(queryUrlPage, repo.getUserId(), decryptedPassword,decryptedPersonalAccessToken);
            JSONArray jsonArray = parseAsArray(response);
            for (Object item : jsonArray) {
                JSONObject jsonObject = (JSONObject) item;
                String sha = str(jsonObject, "sha");
                JSONObject commitObject = (JSONObject) jsonObject.get("commit");
                JSONObject commitAuthorObject = (JSONObject) commitObject.get("author");
                String message = str(commitObject, "message");
                String author = str(commitAuthorObject, "name");
                long timestamp = new DateTime(str(commitAuthorObject, "date"))
                        .getMillis();
                JSONObject authorObject = (JSONObject) jsonObject.get("author");
                String authorLogin = "";
                if (authorObject != null) {
                    authorLogin = str(authorObject, "login");
                }
                JSONArray parents = (JSONArray) jsonObject.get("parents");
                List<String> parentShas = new ArrayList<>();
                if (parents != null) {
                    for (Object parentObj : parents) {
                        parentShas.add(str((JSONObject) parentObj, "sha"));
                    }
                }

                Commit commit = new Commit();
                commit.setTimestamp(System.currentTimeMillis());
                commit.setScmUrl(repo.getRepoUrl());
                commit.setScmBranch(repo.getBranch());
                commit.setScmRevisionNumber(sha);
                commit.setScmParentRevisionNumbers(parentShas);
                commit.setScmAuthor(author);
                commit.setScmAuthorLogin(authorLogin);
                commit.setScmCommitLog(message);
                commit.setScmCommitTimestamp(timestamp);
                commit.setNumberOfChanges(1);
                commit.setType(getCommitType(CollectionUtils.size(parents), message, commitExclusionPatterns));
                commits.add(commit);
            }
            if (CollectionUtils.isEmpty(jsonArray)) {
                lastPage = true;
            } else {
                if (isThisLastPage(response)) {
                    lastPage = true;
                } else {
                    lastPage = false;
                    queryUrlPage = getNextPageUrl(response);
                }
            }
        }
        return commits;
    }
@ Override public List < Commit > getCommits ( GitHubRepo repo , boolean firstRun , List < Pattern > commitExclusionPatterns ) throws RestClientException , MalformedURLException , HygieiaException { List < Commit > commits = new ArrayList < > ( ) ; String repoUrl = ( String ) repo . getOptions ( ) . get ( "url" ) ; GitHubParsed gitHubParsed = new GitHubParsed ( repoUrl ) ; String apiUrl = gitHubParsed . getApiUrl ( ) ; String queryUrl = apiUrl . concat ( "/commits?sha=" + repo . getBranch ( ) + "&since=" + getTimeForApi ( getRunDate ( repo , firstRun ) ) ) ; String decryptedPassword = decryptString ( repo . getPassword ( ) , settings . getKey ( ) ) ; String personalAccessToken = ( String ) repo . getOptions ( ) . get ( "personalAccessToken" ) ; String decryptedPersonalAccessToken = decryptString ( personalAccessToken , settings . getKey ( ) ) ; boolean lastPage = false ; String queryUrlPage = queryUrl ; while ( ! lastPage ) { LOG . info ( "Executing " + queryUrlPage ) ; ResponseEntity < String > response = makeRestCall ( queryUrlPage , repo . getUserId ( ) , decryptedPassword , decryptedPersonalAccessToken ) ; JSONArray jsonArray = parseAsArray ( response ) ; for ( Object item : jsonArray ) { JSONObject jsonObject = ( JSONObject ) item ; String sha = str ( jsonObject , "sha" ) ; JSONObject commitObject = ( JSONObject ) jsonObject . get ( "commit" ) ; JSONObject commitAuthorObject = ( JSONObject ) commitObject . get ( "author" ) ; String message = str ( commitObject , "message" ) ; String author = str ( commitAuthorObject , "name" ) ; long timestamp = new DateTime ( str ( commitAuthorObject , "date" ) ) . getMillis ( ) ; JSONObject authorObject = ( JSONObject ) jsonObject . get ( "author" ) ; String authorLogin = "" ; if ( authorObject != null ) { authorLogin = str ( authorObject , "login" ) ; } JSONArray parents = ( JSONArray ) jsonObject . get ( "parents" ) ; List < String > parentShas = new ArrayList < > ( ) ; if ( parents != null ) { for ( Object parentObj : parents ) { parentShas . add ( str ( ( JSONObject ) parentObj , "sha" ) ) ; } } Commit commit = new Commit ( ) ; commit . setTimestamp ( System . currentTimeMillis ( ) ) ; commit . setScmUrl ( repo . getRepoUrl ( ) ) ; commit . setScmBranch ( repo . getBranch ( ) ) ; commit . setScmRevisionNumber ( sha ) ; commit . setScmParentRevisionNumbers ( parentShas ) ; commit . setScmAuthor ( author ) ; commit . setScmAuthorLogin ( authorLogin ) ; commit . setScmCommitLog ( message ) ; commit . setScmCommitTimestamp ( timestamp ) ; commit . setNumberOfChanges ( 1 ) ; commit . setType ( getCommitType ( CollectionUtils . size ( parents ) , message , commitExclusionPatterns ) ) ; commits . add ( commit ) ; } if ( CollectionUtils . isEmpty ( jsonArray ) ) { lastPage = true ; } else { if ( isThisLastPage ( response ) ) { lastPage = true ; } else { lastPage = false ; queryUrlPage = getNextPageUrl ( response ) ; } } } return commits ; }
Gets commits for a given repo
@param repo
@param firstRun
@return list of commits
@throws RestClientException
@throws MalformedURLException
@throws HygieiaException