hudson.plugins.git.GitChangeSet Java Examples

The following examples show how to use hudson.plugins.git.GitChangeSet. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GitLabBrowser.java    From gitlab-branch-source-plugin with MIT License 6 votes vote down vote up
@Override
public URL getFileLink(GitChangeSet.Path path) throws IOException {
    if (path.getEditType().equals(EditType.DELETE)) {
        return diffLink(path);
    } else {
        return new URL(
            getUriTemplateFromServer(getProjectUrl())
                .literal("/blob")
                .path(UriTemplateBuilder.var("changeSet"))
                .path(UriTemplateBuilder.var("path", true))
                .build()
                .set("changeSet", path.getChangeSet().getId())
                .set("path", splitPath(path.getPath()))
                .expand()
        );
    }
}
 
Example #2
Source File: ChangeLogIssueKeyExtractor.java    From atlassian-jira-software-cloud-plugin with Apache License 2.0 5 votes vote down vote up
public Set<String> extractIssueKeys(final WorkflowRun workflowRun) {

        final Set<IssueKey> allIssueKeys = new HashSet<>();
        final List<ChangeLogSet<? extends ChangeLogSet.Entry>> changeSets =
                workflowRun.getChangeSets();

        for (ChangeLogSet<? extends ChangeLogSet.Entry> changeSet : changeSets) {
            final Object[] changeSetEntries = changeSet.getItems();
            for (Object item : changeSetEntries) {
                final ChangeLogSet.Entry changeSetEntry = (ChangeLogSet.Entry) item;

                if (changeSetEntry instanceof GitChangeSet) {
                    allIssueKeys.addAll(
                            IssueKeyStringExtractor.extractIssueKeys(
                                    ((GitChangeSet) changeSetEntry).getComment()));
                }
                allIssueKeys.addAll(
                        IssueKeyStringExtractor.extractIssueKeys(changeSetEntry.getMsg()));

                if (allIssueKeys.size() >= ISSUE_KEY_MAX_LIMIT) {
                    break;
                }
            }
        }

        return allIssueKeys
                .stream()
                .limit(ISSUE_KEY_MAX_LIMIT)
                .map(IssueKey::toString)
                .collect(Collectors.toSet());
    }
 
Example #3
Source File: ChangeLogExtractorTest.java    From atlassian-jira-software-cloud-plugin with Apache License 2.0 5 votes vote down vote up
private WorkflowRun changeSetWithSquashedCommitsInComment() {
    final GitChangeSet entry = mock(GitChangeSet.class);
    when(entry.getComment())
            .thenReturn(
                    "Squashed Commit title (#12)\n"
                            + "* TEST-3 Fix bug #1\n"
                            + "\n"
                            + "* TEST-4 Fix bug #2\n");
    final ChangeLogSet changeLogSet = mock(ChangeLogSet.class);
    when(changeLogSet.getItems()).thenReturn(new Object[] {entry});
    final WorkflowRun workflowRun = mock(WorkflowRun.class);

    when(workflowRun.getChangeSets()).thenReturn(ImmutableList.of(changeLogSet));
    return workflowRun;
}
 
Example #4
Source File: GitLabBrowser.java    From gitlab-branch-source-plugin with MIT License 5 votes vote down vote up
@Override
public URL getChangeSetLink(GitChangeSet changeSet) throws IOException {
    return new URL(
        commitUriTemplate(getProjectUrl())
            .set("hash", changeSet.getId())
            .expand()
    );
}
 
Example #5
Source File: GitLabBrowser.java    From gitlab-branch-source-plugin with MIT License 5 votes vote down vote up
@Override
public URL getDiffLink(GitChangeSet.Path path) throws IOException {
    if (path.getEditType() != EditType.EDIT || path.getSrc() == null || path.getDst() == null
        || path.getChangeSet().getParentCommit() == null) {
        return null;
    }
    return diffLink(path);
}
 
Example #6
Source File: GitLabBrowser.java    From gitlab-branch-source-plugin with MIT License 5 votes vote down vote up
private URL diffLink(GitChangeSet.Path path) throws IOException {
    return new URL(
        getUriTemplateFromServer(getProjectUrl())
            .literal("/commit")
            .path(UriTemplateBuilder.var("changeSet"))
            .fragment(UriTemplateBuilder.var("diff"))
            .build()
            .set("changeSet", path.getChangeSet().getId())
            .set("diff", "#diff-" + getIndexOfPath(path))
            .expand()
    );
}
 
Example #7
Source File: GiteaBrowser.java    From gitea-plugin with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public URL getChangeSetLink(GitChangeSet changeSet) throws IOException {
    return new URL(
            UriTemplate.buildFromTemplate(getRepoUrl())
                    .literal("/commit")
                    .path(UriTemplateBuilder.var("changeSet"))
                    .build()
                    .set("changeSet", changeSet.getId())
                    .expand()
    );
}
 
Example #8
Source File: GiteaBrowserTest.java    From gitea-plugin with MIT License 5 votes vote down vote up
private Path findPath(GitChangeSet changeSet, String path) throws Exception {
    for (final Path p : changeSet.getPaths()) {
        if (path.equals(p.getPath())) {
            return p;
        }
    }
    return null;
}
 
Example #9
Source File: AddComment.java    From jira-ext-plugin with Apache License 2.0 5 votes vote down vote up
private String buildComment(Optional<ChangeLogSet.Entry> change,
                            EnvVars environment)
{
    String finalComment = commentText;
    finalComment = environment.expand(finalComment);

    if (!change.isPresent())
    {
        return finalComment;
    }

    String message = "";
    ChangeLogSet.Entry entry = change.get();
    if (entry instanceof GitChangeSet)
    {
        message = ((GitChangeSet) entry).getComment();
    }
    else
    {
        message = entry.getMsg();
    }

    finalComment = StringUtils.replace(finalComment, "$AUTHOR", (entry.getAuthor() == null ? "null" : entry.getAuthor().getDisplayName()));
    finalComment = StringUtils.replace(finalComment, "$COMMIT_ID", entry.getCommitId());
    finalComment = StringUtils.replace(finalComment, "$COMMIT_DATE",
            DATE_FORMAT.format(new Date(entry.getTimestamp())));
    finalComment = StringUtils.replace(finalComment, "$COMMIT_MESSAGE", message);
    return finalComment;
}
 
Example #10
Source File: MockChangeLogUtil.java    From jira-ext-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Mock a GitChangeSet -- the GitChangeSet exposes a one line message in getMessage() and
 * the full text in getComment()
 *
 * @param ticketMessage
 * @param ticketComment
 * @return
 */
public static ChangeLogSet.Entry mockGitCommit(String ticketMessage, String ticketComment)
{
    GitChangeSet gitChangeSet = mock(GitChangeSet.class);
    when(gitChangeSet.getMsg()).thenReturn(ticketMessage);
    when(gitChangeSet.getComment()).thenReturn(ticketComment);
    User mockUser = mock(User.class);
    when(mockUser.toString()).thenReturn("dalvizu");
    when(gitChangeSet.getAuthor()).thenReturn(mockUser);
    when(gitChangeSet.getCommitId()).thenReturn("mockCommitId");
    return gitChangeSet;
}
 
Example #11
Source File: GiteaBrowserTest.java    From gitea-plugin with MIT License 4 votes vote down vote up
private GitChangeSet loadChangeSet(String resourceName) throws Exception {
    try (InputStream is = GiteaBrowserTest.class.getResourceAsStream(resourceName)) {
        return new GitChangeLogParser(false).parse(is).get(0);
    }
}
 
Example #12
Source File: MentionedInCommitStrategy.java    From jira-ext-plugin with Apache License 2.0 4 votes vote down vote up
/**
 * Parse Jira ticket numbers, ie SSD-101, out of the given ChangeLogSet.Entry.
 *
 * <p>Ticket number should be somewhere in the commit message</p>
 *
 * @param  change
 *
 * @return
 */
@Override
public List<JiraCommit> getJiraIssuesFromChangeSet(final ChangeLogSet.Entry change)
{
    final List<JiraCommit> result = new ArrayList<>();
    final List<String> foundTickets = new ArrayList<>();

    for (String validJiraPrefix : Config.getGlobalConfig().getJiraTickets())
    {
        String msg = change.getMsg();
        if (change instanceof GitChangeSet)
        {
          msg = ((GitChangeSet) change).getComment();
        }

        while (StringUtils.isNotEmpty(msg))
        {
            final int foundPos = StringUtils.indexOf(msg, validJiraPrefix);

            if (foundPos == -1)
            {
                break;
            }

            final String firstOccurrence = msg.substring(foundPos + validJiraPrefix.length());
            final String regex = "\\A[0-9]*";
            final Pattern pattern = Pattern.compile(regex);
            final Matcher matcher = pattern.matcher(firstOccurrence);

            if (!matcher.find())
            {
                break;
            }
            /**
             * It is totally unclear why a regex for the entire
             * Jira ticket identifier is not a configuration item
             * It is strange to be seperating the ticket number from the
             * prefix, just to put it back together again -
             * without using either seperately.
             *
             * This would be a trivial change to the config, and
             * #probably# not break any existing code other than these isolated
             * areas where the prefix is being searched.
             */

            final String ticketNumber = matcher.group();

            if (StringUtils.isEmpty(ticketNumber))
            {
                break;
            }

            final String resultingTicket = validJiraPrefix + ticketNumber;

            if (!foundTickets.contains(resultingTicket))
            {
                foundTickets.add(resultingTicket);
                result.add(new JiraCommit(resultingTicket, change));
            }

            msg = firstOccurrence;
        }
    }

    return result;
}