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 String buildComment(User user, String repositoryName, Commit commit) { if (Strings.isNullOrEmpty(user.getUsername())) { return String.format( "%s mentioned this issue in [a commit of %s|%s] \r\n " + "*%s* : %s", user.getName(), repositoryName, commit.getUrl(), getDateAsString(commit.getTimestamp()), commit.getMessage()); } else { return String.format( "[%s|%s] mentioned this issue in [a commit of %s|%s] \r\n" + "*%s* : %s", user.getName(), gitLabService.getUserUrl(user.getUsername()), repositoryName, commit.getUrl(), getDateAsString(commit.getTimestamp()), commit.getMessage()); } }
public String buildCommentForTransition(User user, String repositoryName, Commit commit) { if (Strings.isNullOrEmpty(user.getUsername())) { return String.format( "%s changed status of this issue in [a commit of %s|%s] to *%s* \r\n\r\n " + "*%s* : %s", user.getName(), repositoryName, commit.getUrl(), JiraService.TRANSITION_HOLDER, getDateAsString(commit.getTimestamp()), commit.getMessage()); } else { return String.format( "[%s|%s] changed status of this issue in [a commit of %s|%s] to *%s* \r\n\r\n" + "*%s* : %s", user.getName(), gitLabService.getUserUrl(user.getUsername()), repositoryName, commit.getUrl(), JiraService.TRANSITION_HOLDER, getDateAsString(commit.getTimestamp()), commit.getMessage()); } }