private TableModel commentsModel(List<GitlabNote> notes) { Object[] columnNames = {"Author", "Date", "Text"}; Object[][] data = new Object[notes.size()][columnNames.length]; int i = 0; notes.sort((o1, o2) -> o2.getCreatedAt().compareTo(o1.getCreatedAt())); for(GitlabNote mergeRequest : notes) { Object[] row = new Object[columnNames.length]; row[0] = mergeRequest.getAuthor().getName(); row[1] = mergeRequest.getCreatedAt(); row[2] = mergeRequest.getBody(); data[i] = row; i++; } return new ReadOnlyTableModel(data, columnNames); } }
@Override public List<Comment> getComments() { final List<Comment> found = new ArrayList<>(); try { final List<GitlabNote> notes = gitlabApi.getAllNotes(mergeRequest); for (final GitlabNote note : notes) { final String identifier = note.getId() + ""; final String content = note.getBody(); final String type = "PR"; final List<String> specifics = new ArrayList<>(); final Comment comment = new Comment(identifier, content, type, specifics); found.add(comment); } } catch (final Throwable e) { violationsLogger.log(SEVERE, "Could not get comments", e); } return found; }
/** * Delete an Issue Note * * @param projectId The project id * @param issueId The issue id * @param noteToDelete The note to delete * @throws IOException on gitlab api call error */ public void deleteNote(Serializable projectId, Integer issueId, GitlabNote noteToDelete) throws IOException { String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId) + GitlabIssue.URL + "/" + issueId + GitlabNote.URL + "/" + noteToDelete.getId(); retrieve().method(DELETE).to(tailUrl, GitlabNote.class); }
private GitlabNote getLastNote(GitlabMergeRequest gitlabMergeRequest, GitlabAPI api) throws IOException { List<GitlabNote> notes = getNotes(gitlabMergeRequest, api); GitlabNote lastNote = null; if (!notes.isEmpty()) { lastNote = notes.get(notes.size() - 1); LOGGER.info("Last note found: " + lastNote.getBody()); } return lastNote; }
@Override public int compare(GitlabNote o1, GitlabNote o2) { return o1.getCreatedAt().compareTo(o2.getCreatedAt()); } });
@Before public void before() throws Exception { new MockUp<GitlabBuildTrigger.GitlabBuildTriggerDescriptor>() { @Mock String getBotUsername() { return "test-bot-username"; } }; new NonStrictExpectations() {{ api.getCommits(mergeRequest); result = Arrays.asList(commit); trigger.getAssigneeFilter(); result = ""; trigger.getTriggerComment(); result = "test-trigger-comment"; }}; botUser.setUsername("test-bot-username"); commit.setId("test-commit-id"); jenkinsNote.setAuthor(botUser); jenkinsNote.setBody("test-jenkins-note"); jenkinsNote.setCreatedAt(dateFormat.parse("2015-01-01")); triggerNote.setBody("test-trigger-comment"); triggerNote.setCreatedAt(dateFormat.parse("2015-01-02")); }
@Override public void removeComments(final List<Comment> comments) { for (final Comment comment : comments) { try { final GitlabNote noteToDelete = new GitlabNote(); noteToDelete.setId(Integer.parseInt(comment.getIdentifier())); gitlabApi.deleteNote(mergeRequest, noteToDelete); } catch (final Throwable e) { violationsLogger.log( INFO, "Exception thrown when delete note " + comment.getIdentifier() + ". This is probably because of " + "https://github.com/timols/java-gitlab-api/issues/321"); // violationsLogger.log(SEVERE, "Could not delete note " + comment, e); } } }
/** * Delete an Issue Note * * @param projectId The project id * @param issueId The issue id * @param noteToDelete The note to delete * @throws IOException on gitlab api call error */ public void deleteNote(Serializable projectId, Integer issueId, GitlabNote noteToDelete) throws IOException { String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId) + GitlabIssue.URL + "/" + issueId + GitlabNote.URL + "/" + noteToDelete.getId(); retrieve().method(DELETE).to(tailUrl, GitlabNote.class); }
private Map<String, String> getSpecifiedCustomParameters(GitlabMergeRequest gitlabMergeRequest, GitlabAPI api) throws IOException { String botUsername = GitlabBuildTrigger.getDesc().getBotUsername(); // Mention the botUserName in the text using @[botUserName] to indicate a command to the bot. If that is followed by a semicolon and one of the two commands: // USE-PARAMETER for specifying a parameter using the format Key=Value // or REMOVE-PARAMETER for removing a parameter with the given Key Pattern searchPattern = Pattern.compile("@" + botUsername + "\\s*:\\s*(USE|REMOVE)-PARAMETER\\s*:\\s*(\\w+)\\s*(?:=\\s*(.*))?", Pattern.CASE_INSENSITIVE); Map<String, String> customParams = new HashMap<>(); for (GitlabNote note : getNotes(gitlabMergeRequest, api)) { Matcher m = searchPattern.matcher(note.getBody()); // the command to the @botUserName can be given anywhere in the text if (m.find()) { if (m.group(1).equalsIgnoreCase("USE")) { customParams.put(m.group(2), m.group(3)); } else { customParams.remove(m.group(2)); } } } return customParams; }
public int compare(GitlabNote o1, GitlabNote o2) { return o1.getCreatedAt().compareTo(o2.getCreatedAt()); } });
cmapper.setAuthor(repository.createPerson(notes.get(i).getAuthor().getName())); cmapper.setCreationDate(notes.get(i).getCreatedAt()); cmapper.setText(notes.get(i).getBody()); cmapper.setNumber(i + 1); TaskAttribute attribute = data.getRoot().createAttribute(TaskAttribute.PREFIX_COMMENT + (i + 1));
/** * Delete an Issue Note * * @param projectId The project id * @param issueId The issue id * @param noteToDelete The note to delete * @throws IOException on gitlab api call error */ public void deleteNote(Serializable projectId, Integer issueId, GitlabNote noteToDelete) throws IOException { String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId) + GitlabIssue.URL + "/" + issueId + GitlabNote.URL + "/" + noteToDelete.getId(); retrieve().method(DELETE).to(tailUrl, GitlabNote.class); }
if (lastNote != null && lastNote.getBody().equals(triggerComment)) { LOGGER.info("Trigger comment found"); shouldRun = true;
public int compare(GitlabNote o1, GitlabNote o2) { return o1.getCreatedAt().compareTo(o2.getCreatedAt()); } });
/** * Delete a Merge Request Note * * @param mergeRequest The merge request * @param noteToDelete The note to delete * @throws IOException on gitlab api call error */ public void deleteNote(GitlabMergeRequest mergeRequest, GitlabNote noteToDelete) throws IOException { String tailUrl = GitlabProject.URL + "/" + mergeRequest.getProjectId() + GitlabMergeRequest.URL + "/" + mergeRequest.getIid() + GitlabNote.URL + "/" + noteToDelete.getId(); retrieve().method(DELETE).to(tailUrl, GitlabNote.class); }
/** * Delete a Merge Request Note * * @param mergeRequest The merge request * @param noteToDelete The note to delete * @throws IOException on gitlab api call error */ public void deleteNote(GitlabMergeRequest mergeRequest, GitlabNote noteToDelete) throws IOException { String tailUrl = GitlabProject.URL + "/" + mergeRequest.getProjectId() + GitlabMergeRequest.URL + "/" + mergeRequest.getIid() + GitlabNote.URL + "/" + noteToDelete.getId(); retrieve().method(DELETE).to(tailUrl, GitlabNote.class); }
/** * Delete a Merge Request Note * * @param mergeRequest The merge request * @param noteToDelete The note to delete * @throws IOException on gitlab api call error */ public void deleteNote(GitlabMergeRequest mergeRequest, GitlabNote noteToDelete) throws IOException { String tailUrl = GitlabProject.URL + "/" + mergeRequest.getProjectId() + GitlabMergeRequest.URL + "/" + mergeRequest.getIid() + GitlabNote.URL + "/" + noteToDelete.getId(); retrieve().method(DELETE).to(tailUrl, GitlabNote.class); }