Skip to content

Commit

Permalink
[JENKINS-34395] Fix SCM build for tags
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenc committed Sep 7, 2017
1 parent d094402 commit 909ce64
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
Expand Up @@ -119,6 +119,9 @@ public GitHubSCMBuilder(@NonNull GitHubSCMSource source,
withRefSpec("+refs/pull/" + h.getId() + "/head:refs/remotes/@{remote}/" + head
.getName());
repoUrl = repositoryUrl(h.getSourceOwner(), h.getSourceRepo());
} else if (head instanceof GitHubTagSCMHead) {
withRefSpec("+refs/tags/" + head.getName() + ":refs/tags/" + head.getName());
repoUrl = repositoryUrl(repoOwner, repository);
} else {
withRefSpec("+refs/heads/" + head.getName() + ":refs/remotes/@{remote}/" + head.getName());
repoUrl = repositoryUrl(repoOwner, repository);
Expand Down
Expand Up @@ -33,6 +33,7 @@
import java.util.ArrayList;
import java.util.List;
import jenkins.scm.api.SCMFile;
import org.eclipse.jgit.lib.Constants;
import org.kohsuke.github.GHContent;
import org.kohsuke.github.GHRepository;

Expand Down Expand Up @@ -88,28 +89,28 @@ private Object metadata() throws IOException {
try {
switch (info) {
case DIRECTORY_ASSUMED:
metadata = repo.getDirectoryContent(getPath(), ref);
metadata = repo.getDirectoryContent(getPath(), Constants.R_REFS + ref);
info = TypeInfo.DIRECTORY_CONFIRMED;
resolved = true;
break;
case DIRECTORY_CONFIRMED:
metadata = repo.getDirectoryContent(getPath(), ref);
metadata = repo.getDirectoryContent(getPath(), Constants.R_REFS + ref);
resolved = true;
break;
case NON_DIRECTORY_CONFIRMED:
metadata = repo.getFileContent(getPath(), ref);
metadata = repo.getFileContent(getPath(), Constants.R_REFS + ref);
resolved = true;
break;
case UNRESOLVED:
checkOpen();
try {
metadata = repo.getFileContent(getPath(), ref);
metadata = repo.getFileContent(getPath(), Constants.R_REFS + ref);
info = TypeInfo.NON_DIRECTORY_CONFIRMED;
resolved = true;
} catch (IOException e) {
if (e.getCause() instanceof IOException
&& e.getCause().getCause() instanceof JsonMappingException) {
metadata = repo.getDirectoryContent(getPath(), ref);
metadata = repo.getDirectoryContent(getPath(), Constants.R_REFS + ref);
info = TypeInfo.DIRECTORY_CONFIRMED;
resolved = true;
} else {
Expand All @@ -136,7 +137,7 @@ protected SCMFile newChild(String name, boolean assumeIsDirectory) {
@Override
public Iterable<SCMFile> children() throws IOException {
checkOpen();
List<GHContent> content = repo.getDirectoryContent(getPath(), ref);
List<GHContent> content = repo.getDirectoryContent(getPath(), Constants.R_REFS + ref);
List<SCMFile> result = new ArrayList<>(content.size());
for (GHContent c : content) {
result.add(new GitHubSCMFile(this, c.getName(), c));
Expand Down
Expand Up @@ -116,7 +116,7 @@ public long lastModified() {
}
} else if (revision == null) {
try {
GHRef ref = repo.getRef(StringUtils.removeStart(this.ref, Constants.R_REFS));
GHRef ref = repo.getRef(this.ref);
GHCommit commit = repo.getCommit(ref.getObject().getSha());
return commit.getCommitDate().getTime();
} catch (IOException e) {
Expand All @@ -132,7 +132,7 @@ public SCMProbeStat stat(@NonNull String path) throws IOException {
checkOpen();
try {
int index = path.lastIndexOf('/') + 1;
List<GHContent> directoryContent = repo.getDirectoryContent(path.substring(0, index), ref);
List<GHContent> directoryContent = repo.getDirectoryContent(path.substring(0, index), Constants.R_REFS + ref);
for (GHContent content : directoryContent) {
if (content.getPath().equals(path)) {
if (content.isFile()) {
Expand Down

0 comments on commit 909ce64

Please sign in to comment.