Skip to content
Permalink
Browse files
Allow a source repository to be removed
Reviewed-by: ehelin
  • Loading branch information
rwestberg committed Aug 3, 2020
1 parent 8112650 commit 9a388094be685319c0282949c37dcf979b7a7ded
Showing 7 changed files with 25 additions and 15 deletions.
@@ -654,7 +654,7 @@ private void addSourceBranchWarningComment(List<Comment> comments) throws IOExce
"a branch with the same name as the source branch for this pull request (`" + branch + "`) " +
"is present in the [target repository](" + pr.repository().nonTransformedWebUrl() + "). " +
"If you eventually integrate this pull request then the branch `" + branch + "` " +
"in your [personal fork](" + pr.sourceRepository().nonTransformedWebUrl() + ") will diverge once you sync " +
"in your [personal fork](" + pr.sourceRepository().get().nonTransformedWebUrl() + ") will diverge once you sync " +
"your personal fork with the upstream repository.\n" +
"\n" +
"To avoid this situation, create a new branch for your changes and reset the `" + branch + "` branch. " +
@@ -782,9 +782,11 @@ private void checkStatus() {
newLabels.remove("merge-conflict");
}

var branchNames = pr.repository().branches().stream().map(HostedBranch::name).collect(Collectors.toSet());
if (!pr.repository().url().equals(pr.sourceRepository().url()) && branchNames.contains(pr.sourceRef())) {
addSourceBranchWarningComment(comments);
if (pr.sourceRepository().isPresent()) {
var branchNames = pr.repository().branches().stream().map(HostedBranch::name).collect(Collectors.toSet());
if (!pr.repository().url().equals(pr.sourceRepository().get().url()) && branchNames.contains(pr.sourceRef())) {
addSourceBranchWarningComment(comments);
}
}

if (!PullRequestUtils.isMerge(pr) && PullRequestUtils.containsForeignMerge(pr, localRepo)) {
@@ -96,8 +96,8 @@ public String sourceRef() {
}

@Override
public HostedRepository sourceRepository() {
return null;
public Optional<HostedRepository> sourceRepository() {
return Optional.empty();
}

@Override
@@ -208,7 +208,7 @@ public static void main(String[] args) throws IOException {
issues.add(String.join(",", prIssues));
urls.add(pr.webUrl().toString());

if (pr.sourceRepository().webUrl().equals(uri)) {
if (pr.sourceRepository().isPresent() && pr.sourceRepository().get().webUrl().equals(uri)) {
branches.add(pr.sourceRef());
} else {
branches.add("");
@@ -88,7 +88,7 @@ public interface PullRequest extends Issue {
* Returns the repository the request is created from.
* @return
*/
HostedRepository sourceRepository();
Optional<HostedRepository> sourceRepository();

/**
* Returns the name of the ref the request is intended to be merged into.
@@ -247,8 +247,12 @@ public String sourceRef() {
}

@Override
public HostedRepository sourceRepository() {
return new GitHubRepository(host, json.get("head").get("repo").get("full_name").asString());
public Optional<HostedRepository> sourceRepository() {
if (json.get("head").get("repo").isNull()) {
return Optional.empty();
} else {
return Optional.of(new GitHubRepository(host, json.get("head").get("repo").get("full_name").asString()));
}
}

@Override
@@ -267,9 +267,13 @@ public String sourceRef() {
}

@Override
public HostedRepository sourceRepository() {
return new GitLabRepository((GitLabHost) repository.forge(),
json.get("source_project_id").asInt());
public Optional<HostedRepository> sourceRepository() {
if (json.get("source_project_id").isNull()) {
return Optional.empty();
} else {
return Optional.of(new GitLabRepository((GitLabHost) repository.forge(),
json.get("source_project_id").asInt()));
}
}

@Override
@@ -146,8 +146,8 @@ public String sourceRef() {
}

@Override
public HostedRepository sourceRepository() {
return sourceRepository;
public Optional<HostedRepository> sourceRepository() {
return Optional.of(sourceRepository);
}

@Override

1 comment on commit 9a38809

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented on 9a38809 Aug 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.