Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions .idea/codeStyleSettings.xml

This file was deleted.

3 changes: 0 additions & 3 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion github-pullrequest-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<!-- historical name -->
<artifactId>github-pullrequest</artifactId>
<version>0.1.0-SNAPSHOT</version>
<version>0.1.2-SNAPSHOT</version>
Copy link
Owner

Choose a reason for hiding this comment

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

please remove version change

<packaging>hpi</packaging>

<name>GitHub Integration Plugin</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ public String getUrlName() {
}


public synchronized void removeBranch(String branchName) {
if (nonNull(branches)) {
Copy link
Owner

Choose a reason for hiding this comment

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

you can just getBranches().remove(branchName) and i guess @Nonnull String branchName argument

branches.remove(branchName);
}
}

/**
* Searches for all builds performed in the runs of current job.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import antlr.ANTLRException;
import com.github.kostyasha.github.integration.branch.events.GitHubBranchEvent;
import com.github.kostyasha.github.integration.branch.events.GitHubBranchEventDescriptor;
import com.github.kostyasha.github.integration.branch.events.impl.GitHubBranchDeletedEvent;
import com.github.kostyasha.github.integration.branch.trigger.JobRunnerForBranchCause;
import com.github.kostyasha.github.integration.generic.GitHubTrigger;
import com.github.kostyasha.github.integration.generic.GitHubTriggerDescriptor;
Expand All @@ -29,6 +30,7 @@
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.IOException;
//import java.util.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
Expand Down Expand Up @@ -163,9 +165,13 @@ public void queueRun(Job<?, ?> job, final String branch) {
/**
* Runs check
*
* synchronizing a method is bad ... we really should just focus on synchronizing the variable localreposittory
* so that it is cleaned up in case multiple events come in ... so we dont' prematurely fire delete events on
* local repo that maybe processing a delete ...
*
* @param branch - branch for check, if null - then all PRs
*/
public void doRun(String branch) {
public synchronized void doRun(String branch) {
if (not(isBuildable()).apply(job)) {
LOG.debug("Job {} is disabled, but trigger run!", isNull(job) ? "<no job>" : job.getFullName());
return;
Expand Down Expand Up @@ -226,7 +232,7 @@ private List<GitHubBranchCause> readyToBuildCauses(GitHubBranchRepository localR
GHRepository remoteRepo = getRemoteRepository();
Set<GHBranch> remoteBranches = branchesToCheck(branch, remoteRepo, localRepository);

List<GitHubBranchCause> causes = checkBranches(remoteBranches, localRepository, listener);
List<GitHubBranchCause> causes = checkBranches(branch, remoteBranches, remoteRepo, localRepository, listener);

/*
* update details about the local repo after the causes are determined as they expect
Expand Down Expand Up @@ -255,7 +261,7 @@ private Set<GHBranch> branchesToCheck(String branch, @Nonnull GHRepository remot
throws IOException {
final LinkedHashSet<GHBranch> ghBranches = new LinkedHashSet<>();

if (branch != null) {
if (branch != null) { // What about DELETED event ? the remote branch is already gone ...
final GHBranch ghBranch = remoteRepo.getBranches().get(branch);
if (ghBranch != null) {
ghBranches.add(ghBranch);
Expand All @@ -267,8 +273,10 @@ private Set<GHBranch> branchesToCheck(String branch, @Nonnull GHRepository remot
return ghBranches;
}

private List<GitHubBranchCause> checkBranches(Set<GHBranch> remoteBranches,
GitHubBranchRepository localRepository, LoggingTaskListenerWrapper listener) {
private List<GitHubBranchCause> checkBranches(String branchName, Set<GHBranch> remoteBranches, @Nonnull GHRepository remoteRepo,
GitHubBranchRepository localRepository, LoggingTaskListenerWrapper listener)
throws IOException {

List<GitHubBranchCause> causes = remoteBranches.stream()
// TODO: update user whitelist filter
.filter(ifSkippedFirstRun(listener, skipFirstRun))
Expand All @@ -277,6 +285,54 @@ private List<GitHubBranchCause> checkBranches(Set<GHBranch> remoteBranches,
.filter(Objects::nonNull)
.collect(Collectors.toList());

// DELETE BRANCH is a special case since the remote branch exists for all the other events
// and there is probably a more elegant solution ...
//boolean processDelete = false;
for (GitHubBranchEvent event : events) {
//processDelete = (event instanceof GitHubBranchDeletedEvent) ? true : false;
//}
//if (processDelete) {
if (event instanceof GitHubBranchDeletedEvent) {
Map<String, GitHubBranch> localBranches = localRepository.getBranches();
GitHubBranch localBranch = localBranches.get(branchName);
if (localBranch != null) {
Map<String, GHBranch> remoteRepoBranches = remoteRepo.getBranches();
if (remoteRepoBranches.get(branchName) == null) {
causes.add(new GitHubBranchCause(localBranch, localRepository, "Branch Deleted", false));
// we probably want to take the localBranch out of the localRepository ...
// cause that also operates on a empty "Set<GHBranch>" stream ...
localRepository.removeBranch(branchName); // so that we don't process a delete on this again ...
LOG.error("Adding cause to trigger delete event for [{}] : {}", localRepository.getFullName(), branchName);
}
}
break; // we only care about delete in the loop ...
}
}
/*
// DELETE BRANCH is a special case since the remote branch exists for all the other events
// and there is probably a more elegant solution ...
boolean processDelete = false;
for (GitHubBranchEvent event : events) {
if (event instanceof GitHubBranchDeletedEvent) {
processDelete = true;
}
}

if (processDelete) {
synchronized (localRepository) {
Map<String, GitHubBranch> localBranches = localRepository.getBranches();
Map<String, GHBranch> remoteRepoBranches = remoteRepo.getBranches();
localBranches.forEach((localBranchName, localBranch) -> {
if (remoteRepoBranches.get(localBranchName) == null) {
causes.add(new GitHubBranchCause(localBranch, localRepository, "Branch Deleted", false));
LOG.error("MG Adding cause to trigger delete event for [{}] : {}", localRepository.getFullName(), localBranchName);
localRepository.removeBranch(localBranchName);
}
});
}
}
*/

LOG.debug("Build trigger count for [{}] : {}", localRepository.getFullName(), causes.size());
return causes;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
</labels>
<lastCommentCreatedAt>2015-01-02 13:11:21.0 UTC</lastCommentCreatedAt>
<sourceRepoOwner>user</sourceRepoOwner>
<inBadState>false</inBadState>
</org.jenkinsci.plugins.github.pullrequest.GitHubPRPullRequest>
</entry>
<entry>
Expand All @@ -42,6 +43,7 @@
</labels>
<lastCommentCreatedAt>2015-01-31 19:21:01.0 UTC</lastCommentCreatedAt>
<sourceRepoOwner>user</sourceRepoOwner>
<inBadState>false</inBadState>
</org.jenkinsci.plugins.github.pullrequest.GitHubPRPullRequest>
</entry>
</pulls>
Expand Down