Search in sources :

Example 1 with Entry

use of hudson.scm.ChangeLogSet.Entry in project hudson-2.x by hudson.

the class ListChangesCommand method act.

@Override
protected int act(List<AbstractBuild<?, ?>> builds) throws IOException {
    // No other permission check needed.
    switch(format) {
        case XML:
            PrintWriter w = new PrintWriter(stdout);
            w.println("<changes>");
            for (AbstractBuild build : builds) {
                w.println("<build number='" + build.getNumber() + "'>");
                ChangeLogSet<?> cs = build.getChangeSet();
                Model p = new ModelBuilder().get(cs.getClass());
                p.writeTo(cs, Flavor.XML.createDataWriter(cs, w));
                w.println("</build>");
            }
            w.println("</changes>");
            w.flush();
            break;
        case CSV:
            for (AbstractBuild build : builds) {
                ChangeLogSet<?> cs = build.getChangeSet();
                for (Entry e : cs) {
                    stdout.printf("%s,%s\n", QuotedStringTokenizer.quote(e.getAuthor().getId()), QuotedStringTokenizer.quote(e.getMsg()));
                }
            }
            break;
        case PLAIN:
            for (AbstractBuild build : builds) {
                ChangeLogSet<?> cs = build.getChangeSet();
                for (Entry e : cs) {
                    stdout.printf("%s\t%s\n", e.getAuthor(), e.getMsg());
                    for (String p : e.getAffectedPaths()) stdout.println("  " + p);
                }
            }
            break;
    }
    return 0;
}
Also used : ModelBuilder(org.kohsuke.stapler.export.ModelBuilder) Entry(hudson.scm.ChangeLogSet.Entry) AbstractBuild(hudson.model.AbstractBuild) Model(org.kohsuke.stapler.export.Model) PrintWriter(java.io.PrintWriter)

Example 2 with Entry

use of hudson.scm.ChangeLogSet.Entry in project hudson-2.x by hudson.

the class AbstractBuild method getCulprits.

/**
 * List of users who committed a change since the last non-broken build till now.
 *
 * <p>
 * This list at least always include people who made changes in this build, but
 * if the previous build was a failure it also includes the culprit list from there.
 * Culprits of unstable build are also included
 * see <a href="http://issues.hudson-ci.org/browse/HUDSON-4617">HUDSON-4617</a> for details
 * @return
 *      can be empty but never null.
 */
@Exported
public Set<User> getCulprits() {
    if (culprits == null) {
        Set<User> r = new HashSet<User>();
        R p = getPreviousCompletedBuild();
        if (p != null && isBuilding()) {
            Result pr = p.getResult();
            if (pr != null && pr.isWorseOrEqualTo(Result.UNSTABLE)) {
                // we are still building, so this is just the current latest information,
                // but we seems to be failing so far, so inherit culprits from the previous build.
                // isBuilding() check is to avoid recursion when loading data from old Hudson, which doesn't record
                // this information
                r.addAll(p.getCulprits());
            }
        }
        for (Entry e : getChangeSet()) r.add(e.getAuthor());
        if (upstreamCulprits) {
            // If we have dependencies since the last successful build, add their authors to our list
            R previousBuild = getPreviousSuccessfulBuild();
            if (previousBuild != null) {
                Map<AbstractProject, AbstractBuild.DependencyChange> depmap = getDependencyChanges(previousBuild);
                for (AbstractBuild.DependencyChange dep : depmap.values()) {
                    for (AbstractBuild<?, ?> b : dep.getBuilds()) {
                        for (Entry entry : b.getChangeSet()) {
                            r.add(entry.getAuthor());
                        }
                    }
                }
            }
        }
        return r;
    }
    return new AbstractSet<User>() {

        public Iterator<User> iterator() {
            return new AdaptedIterator<String, User>(culprits.iterator()) {

                protected User adapt(String id) {
                    return User.get(id);
                }
            };
        }

        public int size() {
            return culprits.size();
        }
    };
}
Also used : AbstractSet(java.util.AbstractSet) AdaptedIterator(hudson.util.AdaptedIterator) Entry(hudson.scm.ChangeLogSet.Entry) HashSet(java.util.HashSet) Exported(org.kohsuke.stapler.export.Exported)

Example 3 with Entry

use of hudson.scm.ChangeLogSet.Entry in project hudson-2.x by hudson.

the class AbstractProject method doRssChangelog.

/**
 * RSS feed for changes in this project.
 */
public void doRssChangelog(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException {
    class FeedItem {

        ChangeLogSet.Entry e;

        int idx;

        public FeedItem(Entry e, int idx) {
            this.e = e;
            this.idx = idx;
        }

        AbstractBuild<?, ?> getBuild() {
            return e.getParent().build;
        }
    }
    List<FeedItem> entries = new ArrayList<FeedItem>();
    for (R r = getLastBuild(); r != null; r = r.getPreviousBuild()) {
        int idx = 0;
        for (ChangeLogSet.Entry e : r.getChangeSet()) entries.add(new FeedItem(e, idx++));
    }
    RSS.forwardToRss(getDisplayName() + ' ' + getScm().getDescriptor().getDisplayName() + " changes", getUrl() + "changes", entries, new FeedAdapter<FeedItem>() {

        public String getEntryTitle(FeedItem item) {
            return "#" + item.getBuild().number + ' ' + item.e.getMsg() + " (" + item.e.getAuthor() + ")";
        }

        public String getEntryUrl(FeedItem item) {
            return item.getBuild().getUrl() + "changes#detail" + item.idx;
        }

        public String getEntryID(FeedItem item) {
            return getEntryUrl(item);
        }

        public String getEntryDescription(FeedItem item) {
            StringBuilder buf = new StringBuilder();
            for (String path : item.e.getAffectedPaths()) buf.append(path).append('\n');
            return buf.toString();
        }

        public Calendar getEntryTimestamp(FeedItem item) {
            return item.getBuild().getTimestamp();
        }

        public String getEntryAuthor(FeedItem entry) {
            return Mailer.descriptor().getAdminAddress();
        }
    }, req, rsp);
}
Also used : Entry(hudson.scm.ChangeLogSet.Entry) SC_INTERNAL_SERVER_ERROR(javax.servlet.http.HttpServletResponse.SC_INTERNAL_SERVER_ERROR) ChangeLogSet(hudson.scm.ChangeLogSet) Entry(hudson.scm.ChangeLogSet.Entry) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList)

Example 4 with Entry

use of hudson.scm.ChangeLogSet.Entry in project blueocean-plugin by jenkinsci.

the class PipelineRunImpl method getChangeSet.

@Override
@Nonnull
public Container<BlueChangeSetEntry> getChangeSet() {
    // If this run is a replay then return the changesets from the original run
    ReplayCause replayCause = run.getCause(ReplayCause.class);
    if (replayCause != null) {
        Run run = this.run.getParent().getBuildByNumber(replayCause.getOriginalNumber());
        if (run == null) {
            return Containers.empty(getLink());
        }
        BlueRun blueRun = BlueRunFactory.getRun(run, parent);
        if (blueRun == null) {
            return Containers.empty(getLink());
        }
        return blueRun.getChangeSet();
    } else {
        Map<String, BlueChangeSetEntry> m = new LinkedHashMap<>();
        int cnt = 0;
        for (ChangeLogSet<? extends Entry> cs : run.getChangeSets()) {
            for (ChangeLogSet.Entry e : cs) {
                cnt++;
                String id = e.getCommitId();
                if (id == null)
                    id = String.valueOf(cnt);
                m.put(id, new ChangeSetResource(organization, e, this));
            }
        }
        return Containers.fromResourceMap(getLink(), m);
    }
}
Also used : ChangeLogSet(hudson.scm.ChangeLogSet) Entry(hudson.scm.ChangeLogSet.Entry) BlueRun(io.jenkins.blueocean.rest.model.BlueRun) StoppableRun(io.jenkins.blueocean.service.embedded.rest.StoppableRun) BlueRun(io.jenkins.blueocean.rest.model.BlueRun) Run(hudson.model.Run) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) BlueChangeSetEntry(io.jenkins.blueocean.rest.model.BlueChangeSetEntry) ReplayCause(org.jenkinsci.plugins.workflow.cps.replay.ReplayCause) ChangeSetResource(io.jenkins.blueocean.service.embedded.rest.ChangeSetResource) LinkedHashMap(java.util.LinkedHashMap) Nonnull(javax.annotation.Nonnull)

Example 5 with Entry

use of hudson.scm.ChangeLogSet.Entry in project jenkins-hipchat-plugin by jlewallen.

the class ActiveNotifier method getChanges.

String getChanges(AbstractBuild r) {
    if (!r.hasChangeSetComputed()) {
        logger.info("No change set computed...");
        return null;
    }
    ChangeLogSet changeSet = r.getChangeSet();
    List<Entry> entries = new LinkedList<Entry>();
    Set<AffectedFile> files = new HashSet<AffectedFile>();
    for (Object o : changeSet.getItems()) {
        Entry entry = (Entry) o;
        logger.info("Entry " + o);
        entries.add(entry);
        files.addAll(entry.getAffectedFiles());
    }
    if (entries.isEmpty()) {
        logger.info("Empty change...");
        return null;
    }
    Set<String> authors = new HashSet<String>();
    for (Entry entry : entries) {
        authors.add(entry.getAuthor().getDisplayName());
    }
    MessageBuilder message = new MessageBuilder(notifier, r);
    message.append("Started by changes from ");
    message.append(StringUtils.join(authors, ", "));
    message.append(" (");
    message.append(files.size());
    message.append(" file(s) changed)");
    return message.appendOpenLink().toString();
}
Also used : AffectedFile(hudson.scm.ChangeLogSet.AffectedFile) Entry(hudson.scm.ChangeLogSet.Entry) ChangeLogSet(hudson.scm.ChangeLogSet) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet)

Aggregations

Entry (hudson.scm.ChangeLogSet.Entry)5 ChangeLogSet (hudson.scm.ChangeLogSet)3 HashSet (java.util.HashSet)2 AbstractBuild (hudson.model.AbstractBuild)1 Run (hudson.model.Run)1 AffectedFile (hudson.scm.ChangeLogSet.AffectedFile)1 AdaptedIterator (hudson.util.AdaptedIterator)1 BlueChangeSetEntry (io.jenkins.blueocean.rest.model.BlueChangeSetEntry)1 BlueRun (io.jenkins.blueocean.rest.model.BlueRun)1 ChangeSetResource (io.jenkins.blueocean.service.embedded.rest.ChangeSetResource)1 StoppableRun (io.jenkins.blueocean.service.embedded.rest.StoppableRun)1 PrintWriter (java.io.PrintWriter)1 AbstractSet (java.util.AbstractSet)1 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 GregorianCalendar (java.util.GregorianCalendar)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 Nonnull (javax.annotation.Nonnull)1 SC_INTERNAL_SERVER_ERROR (javax.servlet.http.HttpServletResponse.SC_INTERNAL_SERVER_ERROR)1