Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow a source repository to be removed #708

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -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