Java Code Examples for hudson.scm.ChangeLogSet#Entry

The following examples show how to use hudson.scm.ChangeLogSet#Entry . 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: ZulipNotifier.java    From zulip-plugin with MIT License 6 votes vote down vote up
private String getChangeSet(Run<?, ?> build) {
    StringBuilder changeString = new StringBuilder();
    RunChangeSetWrapper wrapper = new RunChangeSetWrapper(build);
    if (!wrapper.hasChangeSetComputed()) {
        changeString.append("Could not determine changes since last build.");
    } else if (wrapper.hasChangeSet()) {
        // If there seems to be a commit message at all, try to list all the changes.
        changeString.append("Changes since last build:\n");
        for (ChangeLogSet<? extends ChangeLogSet.Entry> changeLogSet : wrapper.getChangeSets()) {
            for (ChangeLogSet.Entry e : changeLogSet) {
                String commitMsg = e.getMsg().trim();
                if (commitMsg.length() > 47) {
                    commitMsg = commitMsg.substring(0, 46) + "...";
                }
                String author = e.getAuthor().getDisplayName();
                changeString.append("\n* `").append(author).append("` ").append(commitMsg);
            }
        }
    }
    return changeString.toString();
}
 
Example 2
Source File: GithubIssueTest.java    From blueocean-plugin with MIT License 6 votes vote down vote up
@Test
public void changeSetJobParentNotMultibranch() throws Exception {
    AbstractFolder project = mock(AbstractFolder.class);
    Job job = mock(MockJob.class);
    Run run = mock(Run.class);
    ChangeLogSet logSet = mock(ChangeLogSet.class);
    ChangeLogSet.Entry entry = mock(ChangeLogSet.Entry.class);

    when(project.getProperties()).thenReturn(new DescribableList(project));
    when(entry.getParent()).thenReturn(logSet);
    when(logSet.getRun()).thenReturn(run);
    when(run.getParent()).thenReturn(job);
    when(job.getParent()).thenReturn(project);

    when(entry.getMsg()).thenReturn("Closed #123 #124");

    Collection<BlueIssue> resolved = BlueIssueFactory.resolve(entry);
    Assert.assertEquals(0, resolved.size());
}
 
Example 3
Source File: BlueJiraIssue.java    From blueocean-plugin with MIT License 6 votes vote down vote up
@Override
public Collection<BlueIssue> getIssues(ChangeLogSet.Entry changeSetEntry) {
    Run run = changeSetEntry.getParent().getRun();
    final JiraSite site = JiraSite.get(run.getParent());
    if (site == null) {
        return null;
    }
    final JiraBuildAction action = run.getAction(JiraBuildAction.class);
    if (action == null) {
        return null;
    }
    Collection<String> issueKeys = findIssueKeys(changeSetEntry.getMsg(), site.getIssuePattern());
    Iterable<BlueIssue> transformed = Iterables.transform(issueKeys,
                                                          s -> BlueJiraIssue.create(site, action.getIssue(s)));
    return ImmutableList.copyOf(Iterables.filter(transformed, Predicates.notNull()));
}
 
Example 4
Source File: ChangelogReader.java    From fabric-beta-publisher-plugin with MIT License 6 votes vote down vote up
static ChangeLogSet<? extends ChangeLogSet.Entry> getChangeLogSet(Run<?, ?> build) {
    if (build instanceof AbstractBuild) {
        return ((AbstractBuild<?, ?>) build).getChangeSet();
    }
    ItemGroup<?> itemGroup = build.getParent().getParent();
    for (Item item : itemGroup.getItems()) {
        if (!item.getFullDisplayName().equals(build.getFullDisplayName())
                && !item.getFullDisplayName().equals(build.getParent().getFullDisplayName())) {
            continue;
        }

        for (Job<?, ?> job : item.getAllJobs()) {
            if (job instanceof AbstractProject<?, ?>) {
                AbstractProject<?, ?> project = (AbstractProject<?, ?>) job;
                return project.getBuilds().getLastBuild().getChangeSet();
            }
        }
    }
    return ChangeLogSet.createEmpty(build);
}
 
Example 5
Source File: MentionedInCommitStrategyTest.java    From jira-ext-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void testSimpleCase()
        throws Exception
{
    List<ChangeLogSet.Entry> validChanges = Arrays.asList(
            MockChangeLogUtil.mockChangeLogSetEntry("Hello World [FOO-101]"),
            MockChangeLogUtil.mockChangeLogSetEntry("FOO-101 ticket at start"),
            MockChangeLogUtil.mockChangeLogSetEntry("In the middle FOO-101 of the message"),
            MockChangeLogUtil.mockChangeLogSetEntry("Weird characters FOO-101: next to it"));
    for (ChangeLogSet.Entry change : validChanges)
    {
        assertThat(strategy.getJiraIssuesFromChangeSet(change).size(), equalTo(1));
        assertThat(strategy.getJiraIssuesFromChangeSet(change).get(0).getJiraTicket(), equalTo("FOO-101"));
    }

}
 
Example 6
Source File: JiraSCMListenerTest.java    From blueocean-plugin with MIT License 6 votes vote down vote up
private static ChangeLogSet build( String... texts) {
    List<ChangeLogSet.Entry> entries = Arrays.asList( texts ).stream().map( text -> {
        final ChangeLogSet.Entry entry = mock(ChangeLogSet.Entry.class);
        when(entry.getMsg()).thenReturn(text);
        return  entry;
    } ).collect( Collectors.toList() );

    return new ChangeLogSet<ChangeLogSet.Entry>(null, null) {
        @Override
        public boolean isEmptySet() {
            return false;
        }

        @Override
        public Iterator<Entry> iterator() {
            return entries.iterator();
        }
    };
}
 
Example 7
Source File: FactsBuilder.java    From office-365-connector-plugin with Apache License 2.0 6 votes vote down vote up
public void addDevelopers() {
    if (!(run instanceof RunWithSCM)) {
        return;
    }
    RunWithSCM runWithSCM = (RunWithSCM) run;

    List<ChangeLogSet<ChangeLogSet.Entry>> sets = runWithSCM.getChangeSets();

    Set<User> authors = new HashSet<>();
    sets.stream()
            .filter(set -> set instanceof ChangeLogSet)
            .forEach(set -> set
                    .forEach(entry -> authors.add(entry.getAuthor())));

    addFact(NAME_DEVELOPERS, StringUtils.join(sortUsers(authors), ", "));
}
 
Example 8
Source File: MentionedInCommitStrategyTest.java    From jira-ext-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void testTicketRepeatsItself()
{
    ChangeLogSet.Entry entry = MockChangeLogUtil.mockChangeLogSetEntry("FOO-101 is in the message twice FOO-101");
    assertThat(strategy.getJiraIssuesFromChangeSet(entry).size(), equalTo(1));
    assertThat(strategy.getJiraIssuesFromChangeSet(entry),
            hasItem(Matchers.<JiraCommit>hasProperty("jiraTicket", equalTo("FOO-101"))));
}
 
Example 9
Source File: FabricBetaPublisher.java    From fabric-beta-publisher-plugin with MIT License 5 votes vote down vote up
/**
 * @return true if all APKs have been published successfully.
 */
private boolean publishFabric(Run build, EnvVars environment, FilePath workspace, PrintStream logger,
                              ChangeLogSet<? extends ChangeLogSet.Entry> changeLogSet)
        throws InterruptedException, IOException {
    logger.println("Fabric Beta Publisher Plugin:");

    File manifestFile = getManifestFile();

    File crashlyticsToolsFile = prepareCrashlytics(logger, manifestFile);
    if (crashlyticsToolsFile == null) {
        return false;
    }

    String releaseNotes = getReleaseNotes(
            changeLogSet, releaseNotesType, releaseNotesParameter, releaseNotesFile, environment, workspace);

    EnvVarsAction envVarsAction = null;
    if (!Strings.isNullOrEmpty(organization)) {
        envVarsAction = new EnvVarsAction();
    } else {
        logger.println("Skipped constructing Fabric Beta link because organization is not set.");
    }

    List<FilePath> apkFilePaths = getApkFilePaths(environment, workspace);
    boolean success = !apkFilePaths.isEmpty();
    for (int apkIndex = 0; apkIndex < apkFilePaths.size(); apkIndex++) {
        success &= uploadApkFile(envVarsAction, apkIndex, environment, logger, manifestFile, crashlyticsToolsFile,
                releaseNotes, apkFilePaths.get(apkIndex));
    }
    if (envVarsAction != null) {
        build.addAction(envVarsAction);
    }
    FileUtils.delete(logger, manifestFile, crashlyticsToolsFile);
    return success;
}
 
Example 10
Source File: GithubIssueTest.java    From blueocean-plugin with MIT License 5 votes vote down vote up
@Test
public void changeSetEntry() throws Exception {
    MultiBranchProject project = mock(MultiBranchProject.class);
    Job job = mock(MockJob.class);
    Run run = mock(Run.class);
    ChangeLogSet logSet = mock(ChangeLogSet.class);
    ChangeLogSet.Entry entry = mock(ChangeLogSet.Entry.class);

    when(project.getProperties()).thenReturn(new DescribableList(project));
    when(entry.getParent()).thenReturn(logSet);
    when(logSet.getRun()).thenReturn(run);
    when(run.getParent()).thenReturn(job);
    when(job.getParent()).thenReturn(project);

    GitHubSCMSource source = new GitHubSCMSource("foo", null, null, null, "example", "repo");
    when(project.getSCMSources()).thenReturn(Lists.newArrayList(source));

    when(entry.getMsg()).thenReturn("Closed #123 #124");

    Collection<BlueIssue> resolved = BlueIssueFactory.resolve(entry);
    Assert.assertEquals(2, resolved.size());

    Map<String, BlueIssue> issueMap = Maps.uniqueIndex(resolved, new Function<BlueIssue, String>() {
        @Override
        public String apply(BlueIssue input) {
            return input.getId();
        }
    });

    BlueIssue issue123 = issueMap.get("#123");
    Assert.assertEquals("https://github.com/example/repo/issues/123", issue123.getURL());

    BlueIssue issue124 = issueMap.get("#124");
    Assert.assertEquals("https://github.com/example/repo/issues/124", issue124.getURL());
}
 
Example 11
Source File: DynamicBuildModel.java    From DotCi with MIT License 5 votes vote down vote up
private List<String> getChangeSet() {
    final ArrayList<String> changeSet = new ArrayList<>();
    for (final ChangeLogSet.Entry change : this.build.getChangeSet()) {
        changeSet.addAll(change.getAffectedPaths());
    }
    return changeSet;
}
 
Example 12
Source File: RunChangeSetWrapper.java    From zulip-plugin with MIT License 5 votes vote down vote up
public List<? extends ChangeLogSet<? extends ChangeLogSet.Entry>> getChangeSets() {
    if (build instanceof AbstractBuild) {
        return Collections.singletonList(((AbstractBuild<?, ?>) build).getChangeSet());
    } else if (build instanceof WorkflowRun) {
        return ((WorkflowRun) build).getChangeSets();
    }
    return null;
}
 
Example 13
Source File: ReleaseNotesFormatter.java    From fabric-beta-publisher-plugin with MIT License 5 votes vote down vote up
static String getReleaseNotes(ChangeLogSet<? extends ChangeLogSet.Entry> changeLogSet, String releaseNotesType,
                              String releaseNotesParameter, String releaseNotesFile, EnvVars environment,
                              FilePath workspace)
        throws IOException, InterruptedException {
    switch (releaseNotesType) {
        case RELEASE_NOTES_TYPE_NONE:
            return null;
        case RELEASE_NOTES_TYPE_PARAMETER:
            return environment.get(releaseNotesParameter, "");
        case RELEASE_NOTES_TYPE_CHANGELOG:
            StringBuilder sb = new StringBuilder();
            if (!changeLogSet.isEmptySet()) {
                boolean hasManyChangeSets = changeLogSet.getItems().length > 1;
                for (ChangeLogSet.Entry entry : changeLogSet) {
                    sb.append("\n");
                    if (hasManyChangeSets) {
                        sb.append("* ");
                    }
                    sb.append(entry.getMsg());
                }
            }
            return sb.toString();
        case RELEASE_NOTES_TYPE_FILE:
            FilePath releaseNotesFilePath = new FilePath(workspace, environment.expand(releaseNotesFile));
            return releaseNotesFilePath.readToString();
        default:
            return null;
    }
}
 
Example 14
Source File: JiraCommit.java    From jira-ext-plugin with Apache License 2.0 5 votes vote down vote up
public JiraCommit(String jiraTicket, ChangeLogSet.Entry changeSet)
{
    this.jiraTicket = jiraTicket;
    if (changeSet == null)
    {
        this.changeSet = Optional.absent();
    }
    else
    {
        this.changeSet = Optional.of(changeSet);
    }
}
 
Example 15
Source File: JiraSCMListener.java    From blueocean-plugin with MIT License 5 votes vote down vote up
static Collection<String> getIssueKeys(ChangeLogSet<?> changelog, Pattern issuePattern) {
    Set<String> issueKeys = new HashSet<>();
    for (ChangeLogSet.Entry entry : changelog) {
        issueKeys.addAll(BlueJiraIssue.findIssueKeys(entry.getMsg(), issuePattern));
    }
    return issueKeys;
}
 
Example 16
Source File: MentionedInCommitStrategyTest.java    From jira-ext-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void testMultipleTicketNames()
{
    ChangeLogSet.Entry entry = MockChangeLogUtil.mockChangeLogSetEntry("FOO-101 and\n BAR-101 are both in the message");
    assertThat(strategy.getJiraIssuesFromChangeSet(entry).size(), equalTo(2));
    assertThat(strategy.getJiraIssuesFromChangeSet(entry),
            hasItem(Matchers.<JiraCommit>hasProperty("jiraTicket", equalTo("FOO-101"))));
    assertThat(strategy.getJiraIssuesFromChangeSet(entry),
            hasItem(Matchers.<JiraCommit>hasProperty("jiraTicket", equalTo("BAR-101"))));
}
 
Example 17
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 18
Source File: AffectedFileBuilder.java    From office-365-connector-plugin with Apache License 2.0 3 votes vote down vote up
public List<ChangeLogSet> singleChangeLog(AbstractBuild run, String singleAuthor) {
    ChangeLogSet.Entry entryMike = mockEntry(singleAuthor);

    when(entryMike.getAffectedFiles()).thenAnswer(createAnswer(Arrays.asList(new File(), new File())));

    return Arrays.asList(new ChangeLogSetBuilder(run, entryMike));
}
 
Example 19
Source File: AbstractParsingIssueStrategy.java    From jira-ext-plugin with Apache License 2.0 2 votes vote down vote up
/**
 * Parse a JIRA issue key, ie SSD-101, out of the given ChangeLogSet.Entry.
 *
 * @param change
 * @return
 */
protected abstract List<JiraCommit> getJiraIssuesFromChangeSet(ChangeLogSet.Entry change);
 
Example 20
Source File: BlueIssueFactory.java    From blueocean-plugin with MIT License 2 votes vote down vote up
/**
 * @see #resolve(ChangeLogSet.Entry)
 * @param changeSetEntry entry
 * @return issues
 */
public abstract Collection<BlueIssue> getIssues(ChangeLogSet.Entry changeSetEntry);