public static Run<?, ?> getBuildByBranch(Job<?, ?> project, String branchName) { for (Run<?, ?> build : project.getBuilds()) { BuildData data = build.getAction(BuildData.class); MergeRecord merge = build.getAction(MergeRecord.class); if (hasLastBuild(data) && isNoMergeBuild(data, merge)) { for (Branch branch : data.lastBuild.getRevision().getBranches()) { if (branch.getName().endsWith("/" + branchName)) { return build; } } } } return null; }
public boolean revisionMatchesInterest(Revision r) { for (Branch br : r.getBranches()) { if (branchMatchesInterest(br)) return true; } return false; }
public boolean revisionMatchesInterest(Revision r) { for (Branch br : r.getBranches()) { if (branchMatchesInterest(br)) { return true; } } return false; }
public boolean revisionMatchesInterest(Revision r) { for (Branch br : r.getBranches()) { if (branchMatchesInterest(br)) { return true; } } return false; }
protected GitTagAction(Run build, FilePath workspace, Revision revision) { super(build); this.ws = workspace.getRemote(); for (Branch b : revision.getBranches()) { tags.put(b.getName(), new ArrayList<String>()); } }
public Revision sortBranchesForRevision(Revision revision, List<BranchSpec> branchOrder, EnvVars env) { ArrayList<Branch> orderedBranches = new ArrayList<>(revision.getBranches().size()); ArrayList<Branch> revisionBranches = new ArrayList<>(revision.getBranches()); for(BranchSpec branchSpec : branchOrder) { for (Iterator<Branch> i = revisionBranches.iterator(); i.hasNext();) { Branch b = i.next(); if (branchSpec.matches(b.getName(), env)) { i.remove(); orderedBranches.add(b); } } } orderedBranches.addAll(revisionBranches); return new Revision(revision.getSha1(), orderedBranches); }
private Revision objectId2Revision(String singleBranch, ObjectId sha1) { Revision revision = new Revision(sha1); revision.getBranches().add(new Branch(singleBranch, sha1)); return revision; }
@Override public String evaluate(AbstractBuild<?, ?> context, TaskListener listener, String macroName) throws MacroEvaluationException, IOException, InterruptedException { BuildData data = context.getAction(BuildData.class); if (data == null) { return ""; // shall we report an error more explicitly? } Revision lb = data.getLastBuiltRevision(); if (lb==null || lb.getBranches().isEmpty()) return ""; if (all) { StringBuilder buf = new StringBuilder(); for (Branch b : lb.getBranches()) { if (buf.length()>0) buf.append(','); buf.append(format(b)); } return buf.toString(); } else { return format(lb.getBranches().iterator().next()); } }
public void saveBuild(Build build) { lastBuild = build; for (Branch branch : build.revision.getBranches()) { buildsByBranchName.put(fixNull(branch.getName()), build); } }
public void saveBuild(Build build) { lastBuild = build; for(Branch branch : build.marked.getBranches()) { buildsByBranchName.put(fixNull(branch.getName()), build); } for(Branch branch : build.revision.getBranches()) { buildsByBranchName.put(fixNull(branch.getName()), build); } }
public void saveBuild(Build build) { lastBuild = build; for (Branch branch : build.revision.getBranches()) { buildsByBranchName.put(fixNull(branch.getName()), build); } }
public Revision toRevision(IGitAPI git) { ObjectId sha1 = git.revParse(commit); Revision revision = new Revision(sha1); revision.getBranches().add(new Branch("detached", sha1)); return revision; }
/** * Return the revision containing the branch name. * @param branchName name of branch to be searched * @return revision containing branchName * @throws IOException on input or output error * @throws GitException on git error * @throws InterruptedException when interrupted */ public Revision getRevisionContainingBranch(String branchName) throws GitException, IOException, InterruptedException { for(Revision revision : getAllBranchRevisions()) { for(Branch b : revision.getBranches()) { if(b.getName().equals(branchName)) { return revision; } } } return null; }
/** * Return the revision containing the branch name. * * @param branchName * @return * @throws IOException * @throws GitException */ public Revision getRevisionContainingBranch(String branchName) throws GitException, IOException { for (Revision revision : getAllBranchRevisions()) { for (Branch b : revision.getBranches()) { if (b.getName().equals(branchName)) { return revision; } } } return null; }
/** * Return the revision containing the branch name. * * @param branchName * @return * @throws IOException * @throws GitException */ public Revision getRevisionContainingBranch(String branchName) throws GitException, IOException { for (Revision revision : getAllBranchRevisions()) { for (Branch b : revision.getBranches()) { if (b.getName().equals(branchName)) { return revision; } } } return null; }
public Revision toRevision(IGitAPI git) { ObjectId sha1 = git.revParse(commit); Revision revision = new Revision(sha1); revision.getBranches().add(new Branch("detached", sha1)); return revision; }
/** * Return a list of "Revisions" - where a revision knows about all the branch names that refer to * a SHA1. * * @return * @throws IOException * @throws GitException */ public Collection<Revision> getAllBranchRevisions() throws GitException, IOException { Map<ObjectId, Revision> revisions = new HashMap<ObjectId, Revision>(); List<Branch> branches = git.getRemoteBranches(); for (Branch b : branches) { Revision r = revisions.get(b.getSHA1()); if (r == null) { r = new Revision(b.getSHA1()); revisions.put(b.getSHA1(), r); } r.getBranches().add(b); } return revisions.values(); }
public Revision toRevision(GitClient git) throws InterruptedException { if (revision != null) { return revision; } ObjectId sha1 = git.revParse(commit); Revision revision = new Revision(sha1); // Here we do not have any local branches, containing the commit. So... // we are to get all the remote branches, and show them to users, as // they are local final List<Branch> branches = normalizeBranches(git.getBranchesContaining( ObjectId.toString(sha1), true)); revision.getBranches().addAll(branches); return revision; }
@Override public Build prevBuildForChangelog(String singleBranch, BuildData data, GitClient git, BuildChooserContext context) throws InterruptedException, IOException { if (data != null) { ObjectId sha1 = git.revParse("FETCH_HEAD"); // Now we cheat and add the parent as the last build on the branch, so we can // get the changelog working properly-ish. ObjectId parentSha1 = getFirstParent(sha1, git); Revision parentRev = new Revision(parentSha1); parentRev.getBranches().add(new Branch(singleBranch, parentSha1)); int prevBuildNum = 0; Result r = null; Build lastBuild = data.getLastBuildOfBranch(singleBranch); if (lastBuild != null) { prevBuildNum = lastBuild.getBuildNumber(); r = lastBuild.getBuildResult(); } return new Build(parentRev, prevBuildNum, r); } else { //Hmm no sure what to do here, but the git plugin can handle us returning null here return null; } }
@Override public Revision decorateRevisionToBuild(GitSCM scm, Run<?, ?> build, GitClient git, TaskListener listener, Revision marked, Revision rev) throws IOException, InterruptedException, GitException { listener.getLogger().println("Merging " + targetBranch.getName() + " commit " + targetBranch.getRevision().getHash() + " into merge-request head commit " + rev.getSha1String()); checkout(scm, build, git, listener, rev); try { git.setAuthor("Jenkins", /* could parse out of JenkinsLocationConfiguration.get().getAdminAddress() but seems overkill */"nobody@nowhere"); git.setCommitter("Jenkins", "nobody@nowhere"); MergeCommand cmd = git.merge().setRevisionToMerge(ObjectId.fromString(targetBranch.getRevision().getHash())); for (GitSCMExtension ext : scm.getExtensions()) { // By default we do a regular merge, allowing it to fast-forward. ext.decorateMergeCommand(scm, build, git, listener, cmd); } cmd.execute(); } catch (GitException e) { // Try to revert merge conflict markers. checkout(scm, build, git, listener, rev); throw e; } build.addAction(new MergeRecord(targetBranch.getRefSpec().destinationRef(targetBranch.getName()), targetBranch.getRevision().getHash())); // does not seem to be used, but just in case ObjectId mergeRev = git.revParse(Constants.HEAD); listener.getLogger().println("Merge succeeded, producing " + mergeRev.name()); return new Revision(mergeRev, rev.getBranches()); // note that this ensures Build.revision != Build.marked }