This repository has been archived by the owner on May 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from retest/feature/github-support
Feature/GitHub support (1/3)
- Loading branch information
Showing
19 changed files
with
880 additions
and
396 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package org.retest.rebazer; | ||
|
||
import static org.retest.rebazer.config.RebazerConfig.POLL_INTERVAL_DEFAULT; | ||
import static org.retest.rebazer.config.RebazerConfig.POLL_INTERVAL_KEY; | ||
|
||
import org.retest.rebazer.config.RebazerConfig; | ||
import org.retest.rebazer.config.RebazerConfig.RepositoryConfig; | ||
import org.retest.rebazer.config.RebazerConfig.RepositoryHost; | ||
import org.retest.rebazer.config.RebazerConfig.RepositoryTeam; | ||
import org.retest.rebazer.connector.RepositoryConnector; | ||
import org.retest.rebazer.domain.PullRequest; | ||
import org.retest.rebazer.service.PullRequestLastUpdateStore; | ||
import org.retest.rebazer.service.RebaseService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.web.client.RestTemplateBuilder; | ||
import org.springframework.scheduling.annotation.Scheduled; | ||
import org.springframework.stereotype.Service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
@Service | ||
@RequiredArgsConstructor( onConstructor = @__( @Autowired ) ) | ||
public class RebazerService { | ||
|
||
private static final String MSG_REBASE_FAILED = "Rebase failed, this pull request needs some manual love ..."; | ||
|
||
private final RebaseService rebaseService; | ||
private final RebazerConfig rebazerConfig; | ||
private final PullRequestLastUpdateStore pullRequestLastUpdateStore; | ||
|
||
private final RestTemplateBuilder builder; | ||
|
||
@Scheduled( fixedDelayString = "${" + POLL_INTERVAL_KEY + ":" + POLL_INTERVAL_DEFAULT + "}000" ) | ||
public void pollToHandleAllPullRequests() { | ||
rebazerConfig.getHosts().forEach( repoHost -> { | ||
repoHost.getTeams().forEach( repoTeam -> { | ||
repoTeam.getRepos().forEach( repoConfig -> { | ||
handleRepo( repoHost, repoTeam, repoConfig ); | ||
} ); | ||
} ); | ||
} ); | ||
} | ||
|
||
private void handleRepo( final RepositoryHost repoHost, final RepositoryTeam repoTeam, | ||
final RepositoryConfig repoConfig ) { | ||
log.debug( "Processing {}.", repoConfig ); | ||
final RepositoryConnector repoConnector = repoHost.getType().getRepository( repoTeam, repoConfig, builder ); | ||
for ( final PullRequest pullRequest : repoConnector.getAllPullRequests() ) { | ||
handlePullRequest( repoConnector, repoConfig, pullRequest ); | ||
} | ||
log.debug( "Processing done for {}.", repoConfig ); | ||
} | ||
|
||
public void handlePullRequest( final RepositoryConnector repoConnector, final RepositoryConfig repoConfig, | ||
final PullRequest pullRequest ) { | ||
log.debug( "Processing {}.", pullRequest ); | ||
|
||
if ( pullRequestLastUpdateStore.isHandled( repoConfig, pullRequest ) ) { | ||
log.info( "{} is unchanged since last run (last change: {}).", pullRequest, | ||
pullRequestLastUpdateStore.getLastDate( repoConfig, pullRequest ) ); | ||
|
||
} else if ( !repoConnector.greenBuildExists( pullRequest ) ) { | ||
log.info( "Waiting for green build of {}.", pullRequest ); | ||
pullRequestLastUpdateStore.setHandled( repoConfig, pullRequest ); | ||
|
||
} else if ( repoConnector.rebaseNeeded( pullRequest ) ) { | ||
if ( !rebaseService.rebase( repoConfig, pullRequest ) ) { | ||
repoConnector.addComment( pullRequest, MSG_REBASE_FAILED ); | ||
} | ||
// we need to update the "lastUpdate" of a PullRequest to counteract if addComment is called | ||
pullRequestLastUpdateStore.setHandled( repoConfig, repoConnector.getLatestUpdate( pullRequest ) ); | ||
|
||
} else if ( !repoConnector.isApproved( pullRequest ) ) { | ||
log.info( "Waiting for approval of {}.", pullRequest ); | ||
pullRequestLastUpdateStore.setHandled( repoConfig, pullRequest ); | ||
|
||
} else { | ||
log.info( "Merging pull request " + pullRequest ); | ||
repoConnector.merge( pullRequest ); | ||
pullRequestLastUpdateStore.resetAllInThisRepo( repoConfig ); | ||
} | ||
} | ||
|
||
} |
43 changes: 43 additions & 0 deletions
43
src/main/java/org/retest/rebazer/RepositoryHostingTypes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package org.retest.rebazer; | ||
|
||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
|
||
import org.retest.rebazer.config.RebazerConfig.RepositoryConfig; | ||
import org.retest.rebazer.config.RebazerConfig.RepositoryTeam; | ||
import org.retest.rebazer.connector.BitbucketConnector; | ||
import org.retest.rebazer.connector.GithubConnector; | ||
import org.retest.rebazer.connector.RepositoryConnector; | ||
import org.springframework.boot.web.client.RestTemplateBuilder; | ||
|
||
import lombok.Getter; | ||
import lombok.SneakyThrows; | ||
|
||
public enum RepositoryHostingTypes { | ||
|
||
BITBUCKET( "https://bitbucket.org/" ), | ||
GITHUB( "https://github.com/" ), | ||
|
||
; | ||
|
||
@Getter | ||
final URL defaultUrl; | ||
|
||
@SneakyThrows( MalformedURLException.class ) | ||
private RepositoryHostingTypes( final String defaultUrl ) { | ||
this.defaultUrl = new URL( defaultUrl ); | ||
} | ||
|
||
public RepositoryConnector getRepository( final RepositoryTeam repoTeam, final RepositoryConfig repoConfig, | ||
final RestTemplateBuilder templateBuilder ) { | ||
switch ( this ) { | ||
case BITBUCKET: | ||
return new BitbucketConnector( repoTeam, repoConfig, templateBuilder ); | ||
case GITHUB: | ||
return new GithubConnector( repoTeam, repoConfig, templateBuilder ); | ||
default: | ||
throw new RuntimeException( "No Repository defined for provider: " + this ); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 0 additions & 28 deletions
28
src/main/java/org/retest/rebazer/config/BitbucketConfig.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.