private static String getBuildRevision(Run<?, ?> build) { GitLabWebHookCause cause = build.getCause(GitLabWebHookCause.class); if (cause != null) { return cause.getData().getLastCommit(); } BuildData action = build.getAction(BuildData.class); if (action == null) { throw new IllegalStateException("No (git-plugin) BuildData associated to current build"); } Revision lastBuiltRevision = action.getLastBuiltRevision(); if (lastBuiltRevision == null) { throw new IllegalStateException("Last build has no associated commit"); } return action.getLastBuild(lastBuiltRevision.getSha1()).getMarked().getSha1String(); }
public ObjectId getSHA1() { return revision.getSha1(); }
public ObjectId getSHA1() { return revision.getSha1(); }
public ObjectId getSHA1() { return revision.getSha1(); }
/** {@inheritDoc} */ @Deprecated public List<String> showRevision(Revision r) throws GitException, InterruptedException { return showRevision(null, r.getSha1()); }
public Build getLastBuild(ObjectId sha1) { // fast check by first checking most recent build if (lastBuild != null && (lastBuild.revision.getSha1().equals(sha1) || lastBuild.marked.getSha1().equals(sha1))) return lastBuild; try { for(Build b : buildsByBranchName.values()) { if(b.revision.getSha1().equals(sha1) || b.marked.getSha1().equals(sha1)) return b; } return null; } catch(Exception ex) { return null; } }
/** * Return true if the history shows this SHA1 has been built. * False otherwise. * * @param sha1 * @return */ public boolean hasBeenBuilt(ObjectId sha1) { try { for (Build b : buildsByBranchName.values()) { if (b.revision.getSha1().equals(sha1)) { return true; } } return false; } catch (Exception ex) { return false; } }
/** * Return true if the history shows this SHA1 has been built. * False otherwise. * * @param sha1 * @return */ public boolean hasBeenBuilt(ObjectId sha1) { try { for (Build b : buildsByBranchName.values()) { if (b.revision.getSha1().equals(sha1)) { return true; } } return false; } catch (Exception ex) { return false; } }
public int difference(Map<IndexEntry, Revision> item, List<IndexEntry> entries) { int difference = 0; if (entries.size() != item.keySet().size()) return -1; for (IndexEntry entry : entries) { Revision b = null; for (Map.Entry<IndexEntry, Revision> entryAndRevision : item.entrySet()) { IndexEntry e = entryAndRevision.getKey(); if (e.getFile().equals(entry.getFile())) b = entryAndRevision.getValue(); } if (b == null) return -1; if (!entry.getObject().equals(b.getSha1().getName())) difference++; } return difference; }
public int difference(Map<IndexEntry, Revision> item, List<IndexEntry> entries) { int difference = 0; if (entries.size() != item.keySet().size()) { return -1; } for (IndexEntry entry : entries) { Revision b = null; for (IndexEntry e : item.keySet()) { if (e.getFile().equals(entry.getFile())) { b = item.get(e); } } if (b == null) { return -1; } if (!entry.object.equals(b.getSha1())) { difference++; } } return difference; }
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); }
public int difference(Map<IndexEntry, Revision> item, List<IndexEntry> entries) { int difference = 0; if (entries.size() != item.keySet().size()) { return -1; } for (IndexEntry entry : entries) { Revision b = null; for (IndexEntry e : item.keySet()) { if (e.getFile().equals(entry.getFile())) { b = item.get(e); } } if (b == null) { return -1; } if (!entry.object.equals(b.getSha1())) { difference++; } } return difference; }
@Override public RevCommit invoke(Repository repository, VirtualChannel virtualChannel) throws IOException, InterruptedException { try (RevWalk walk = new RevWalk(repository)) { return walk.parseCommit(revToBuild.revision.getSha1()); } } }
public Revision getRevisionForSHA1(ObjectId sha1) throws GitException, IOException { for (Revision revision : getAllBranchRevisions()) { if (revision.getSha1().equals(sha1)) { return revision; } } return null; }
public Revision getRevisionForSHA1(ObjectId sha1) throws GitException, IOException { for (Revision revision : getAllBranchRevisions()) { if (revision.getSha1().equals(sha1)) { return revision; } } return null; }
protected void makeCombination(Map<IndexEntry, Revision> settings) throws InterruptedException { // Assume we are checked out String name = "combine-" + tid + "-" + (idx++); git.branch(name); git.checkout(name); StringBuilder commit = new StringBuilder( "Jenkins generated combination of:\n"); for (Entry<IndexEntry, Revision> setting : settings.entrySet()) { commit.append(' ').append(' '); commit.append(setting.getKey().getFile()); commit.append(' '); commit.append(setting.getValue()); commit.append('\n'); } listener.getLogger().print(commit); for (Entry<IndexEntry, Revision> setting : settings.entrySet()) { IndexEntry submodule = setting.getKey(); Revision branch = setting.getValue(); GitClient subGit = git.subGit(submodule.getFile()); subGit.checkout(branch.getSha1().name()); git.add(submodule.getFile()); } git.commit(commit.toString()); }
public Revision getRevisionForSHA1(ObjectId sha1) throws GitException, IOException, InterruptedException { for(Revision revision : getAllBranchRevisions()) { if(revision.getSha1().equals(sha1)) return revision; } return new Revision(sha1); }
return r.getSha1();
public static void assertRevisionAction(WorkflowRun build) { SCMRevisionAction revisionAction = build.getAction(SCMRevisionAction.class); assertNotNull(revisionAction); SCMRevision revision = revisionAction.getRevision(); assertEquals(GitBranchSCMRevision.class, revision.getClass()); Set<String> expected = new HashSet<>(); List<BuildData> buildDataActions = build.getActions(BuildData.class); if (!buildDataActions.isEmpty()) { // i.e., we have run at least one checkout step, or done a heavyweight checkout to get a single file for (BuildData data : buildDataActions) { expected.add(data.lastBuild.marked.getSha1().getName()); } assertThat(expected, hasItem(((GitBranchSCMRevision) revision).getHash())); } }