Skip to content

Commit

Permalink
Merge pull request #104 from jglick/SCMFileSystem-JENKINS-33273
Browse files Browse the repository at this point in the history
[JENKINS-33273] Jenkinsfile from SCMFileSystem
  • Loading branch information
stephenc committed Jan 16, 2017
2 parents a6058df + e6ce237 commit 29125b2
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 41 deletions.
2 changes: 1 addition & 1 deletion demo/Dockerfile
@@ -1,4 +1,4 @@
FROM jenkins:2.19.3
FROM jenkins:2.32.1

USER root

Expand Down
2 changes: 1 addition & 1 deletion demo/Makefile
@@ -1,5 +1,5 @@
IMAGE=jenkinsci/pipeline-as-code-github-demo
TAG=$(shell perl -n -e 'if (/github-branch-source:(.+)/) {print $$1}' plugins.txt)
TAG=$(shell date -I -u)
DOCKER_RUN=docker run --rm -p 8080:8080 -p 4040:4040 -v $(shell which docker):/usr/bin/docker -v /var/run/docker.sock:/var/run/docker.sock --group-add=$(shell stat -c %g /var/run/docker.sock) -ti

copy-plugins:
Expand Down
60 changes: 30 additions & 30 deletions demo/plugins.txt
@@ -1,47 +1,47 @@
org.jenkins-ci.ui:ace-editor:1.1
org.jenkins-ci.plugins:authentication-tokens:1.3
org.jenkins-ci.plugins:branch-api:1.11
org.jenkins-ci.plugins:cloudbees-folder:5.13
org.jenkins-ci.plugins:credentials:2.1.8
org.jenkins-ci.plugins:branch-api:2.0.0-beta-3
org.jenkins-ci.plugins:cloudbees-folder:5.16
org.jenkins-ci.plugins:credentials:2.1.10
org.jenkins-ci.plugins:display-url-api:0.5
org.jenkins-ci.plugins:docker-commons:1.5
org.jenkins-ci.plugins:docker-workflow:1.9
org.jenkins-ci.plugins:docker-commons:1.6
org.jenkins-ci.plugins:docker-workflow:1.9.1
org.jenkins-ci.plugins:durable-task:1.12
org.jenkins-ci.plugins:git-client:2.0.0
org.jenkins-ci.plugins:git-client:2.2.0
org.jenkins-ci.plugins:git-server:1.7
org.jenkins-ci.plugins:git:3.0.0
com.coravy.hudson.plugins.github:github:1.22.3
org.jenkins-ci.plugins:github-api:1.77
org.jenkins-ci.plugins:github-branch-source:1.10
org.jenkins-ci.plugins:github-organization-folder:1.5
org.jenkins-ci.plugins:git:3.0.2-beta-3-SNAPSHOT
com.coravy.hudson.plugins.github:github:1.25.1
org.jenkins-ci.plugins:github-api:1.84
org.jenkins-ci.plugins:github-branch-source:2.0.0-SNAPSHOT
org.jenkins-ci.ui:handlebars:1.1.1
org.jenkins-ci.plugins.icon-shim:icon-shim:2.0.3
org.jenkins-ci.ui:jquery-detached:1.2.1
org.jenkins-ci.plugins:junit:1.19
org.jenkins-ci.ui:momentjs:1.1.1
org.jenkins-ci.plugins:mailer:1.18
org.jenkins-ci.plugins:matrix-project:1.7.1
org.jenkins-ci.plugins:pipeline-build-step:2.3
org.jenkins-ci.plugins:pipeline-graph-analysis:1.2
org.jenkins-ci.plugins:pipeline-input-step:2.3
org.jenkins-ci.plugins:pipeline-milestone-step:1.1
org.jenkins-ci.plugins:matrix-project:1.8
org.jenkins-ci.plugins:pipeline-build-step:2.4
org.jenkins-ci.plugins:pipeline-github-lib:1.0-SNAPSHOT
org.jenkins-ci.plugins:pipeline-graph-analysis:1.3
org.jenkins-ci.plugins:pipeline-input-step:2.5
org.jenkins-ci.plugins:pipeline-milestone-step:1.3
org.jenkins-ci.plugins:pipeline-stage-step:2.2
org.jenkins-ci.plugins.pipeline-stage-view:pipeline-stage-view:2.1
org.jenkins-ci.plugins.pipeline-stage-view:pipeline-rest-api:2.1
org.jenkins-ci.plugins.pipeline-stage-view:pipeline-stage-view:2.4
org.jenkins-ci.plugins.pipeline-stage-view:pipeline-rest-api:2.4
org.jenkins-ci.plugins:plain-credentials:1.3
org.jenkins-ci.plugins:scm-api:1.3
org.jenkins-ci.plugins:script-security:1.24
org.jenkins-ci.plugins:scm-api:2.0.1-beta-3
org.jenkins-ci.plugins:script-security:1.25
org.jenkins-ci.plugins:ssh-credentials:1.12
org.jenkins-ci.plugins:structs:1.5
org.jenkins-ci.plugins:token-macro:2.0
org.jenkins-ci.plugins.workflow:workflow-aggregator:2.4
org.jenkins-ci.plugins.workflow:workflow-api:2.5
org.jenkins-ci.plugins.workflow:workflow-basic-steps:2.2
org.jenkins-ci.plugins.workflow:workflow-cps-global-lib:2.4
org.jenkins-ci.plugins.workflow:workflow-cps:2.21
org.jenkins-ci.plugins.workflow:workflow-durable-task-step:2.5
org.jenkins-ci.plugins.workflow:workflow-job:2.8
org.jenkins-ci.plugins.workflow:workflow-multibranch:2.9
org.jenkins-ci.plugins.workflow:workflow-scm-step:2.2
org.jenkins-ci.plugins.workflow:workflow-step-api:2.4
org.jenkins-ci.plugins.workflow:workflow-support:2.10
org.jenkins-ci.plugins.workflow:workflow-api:2.8
org.jenkins-ci.plugins.workflow:workflow-basic-steps:2.3
org.jenkins-ci.plugins.workflow:workflow-cps-global-lib:2.5
org.jenkins-ci.plugins.workflow:workflow-cps:2.24-beta-1-SNAPSHOT
org.jenkins-ci.plugins.workflow:workflow-durable-task-step:2.8
org.jenkins-ci.plugins.workflow:workflow-job:2.9
org.jenkins-ci.plugins.workflow:workflow-multibranch:2.10-beta-2-SNAPSHOT
org.jenkins-ci.plugins.workflow:workflow-scm-step:2.3
org.jenkins-ci.plugins.workflow:workflow-step-api:2.7
org.jenkins-ci.plugins.workflow:workflow-support:2.12
Expand Up @@ -38,7 +38,6 @@
import jenkins.scm.api.SCMHead;
import jenkins.scm.api.SCMRevision;
import jenkins.scm.api.SCMSource;
import org.kohsuke.github.GHPullRequest;
import org.kohsuke.github.GHRepository;
import org.kohsuke.github.GitHub;
import org.kohsuke.github.HttpException;
Expand All @@ -53,7 +52,8 @@ protected GitHubSCMFileSystem(GHRepository repo, String ref, @CheckForNull SCMRe
if (rev != null) {
if (rev.getHead() instanceof PullRequestSCMHead) {
PullRequestSCMHead pr = (PullRequestSCMHead) rev.getHead();
this.ref = "refs/pull/" + pr.getNumber() + (pr.isMerge() ? "/merge" : "/head");
assert !pr.isMerge(); // TODO see below
this.ref = ((PullRequestSCMRevision) rev).getPullHash();
} else if (rev instanceof AbstractGitSCMSource.SCMRevisionImpl) {
this.ref = ((AbstractGitSCMSource.SCMRevisionImpl) rev).getHash();
} else {
Expand Down Expand Up @@ -123,19 +123,14 @@ public SCMFileSystem build(@NonNull SCMSource source, @NonNull SCMHead head, @Ch
pr.getSourceBranch(),
rev);
}
ref = "refs/pull/" + pr.getNumber() + (pr.isMerge() ? "/merge" : "/head");
return null; // TODO support merge revisions somehow
} else {
return null;
}

GHRepository repo = github.getUser(src.getRepoOwner()).getRepository(src.getRepository());
if (rev == null) {
if (head instanceof BranchSCMHead) {
rev = new AbstractGitSCMSource.SCMRevisionImpl(head, repo.getBranch(ref).getSHA1());
} else { // if (head instanceof PullRequestSCMHead)
GHPullRequest pr = repo.getPullRequest(((PullRequestSCMHead) head).getNumber());
rev = new PullRequestSCMRevision((PullRequestSCMHead) head, pr.getBase().getSha(), pr.getHead().getSha());
}
rev = new AbstractGitSCMSource.SCMRevisionImpl((BranchSCMHead) head, repo.getBranch(ref).getSHA1());
}
return new GitHubSCMFileSystem(repo, ref, rev);
}
Expand Down

0 comments on commit 29125b2

Please sign in to comment.