public User getUser(Event event) { try { Response<User> userResponse = gitLabService.getUser(event.getUserId()); Preconditions.checkArgument(userResponse.code() == 200); return userResponse.body(); } catch (Exception e) { log.error( "Unable to get gitlab user with id <{}>, comment issue with pusher username <{}>", event.getUserId(), event.getUserName()); return new User(event.getUserId(), null, event.getUserName()); } }
public void performPushEvent(Event event) { Preconditions.checkNotNull(event.getCommits(), "commits array can not be null"); // For each commit, extract jira issues Multimap<String, Commit> jiraIssues = ArrayListMultimap.create(); event .getCommits() .forEach( commit -> jiraService .extractIssuesFromMessage(commit.getMessage()) .forEach(issue -> jiraIssues.put(issue, commit))); if (jiraIssues.size() > 0) { User user = getUser(event); jiraIssues .asMap() .forEach( (issue, commits) -> commentIssue(event.getRepository().getName(), user, commits, issue)); } }