Skip to content
This repository has been archived by the owner on May 28, 2021. It is now read-only.

Feature/GitHub support (1/3) #36

Merged
merged 86 commits into from
Aug 2, 2018
Merged

Feature/GitHub support (1/3) #36

merged 86 commits into from
Aug 2, 2018

Conversation

martin-v
Copy link
Member

No description provided.

*parse json to search for the correct state
*to test rebaseNeeded(PullRequest)
*to test isApproved(PullRequest)
*to test getAllPullRequests(Repository)
*add json to test GithubService methods
*make objects immutable
*to check if there are successful
builds for the PullRequest
*add empty interface Provider
*make methods public to use interface
*add methods to Provider
*implement services
*create class for polling
*adapt polling to get config Objects
*to match yaml configuration
*edit methods to get the right RestTemplate
*adapt classes which called Services
*edit yml.example to realize Team as list
*Add ctor to Provider subclasses with parameter
  info from Provider methods
*Create Provider subclasses with the specific
  RestTemplates to realize clarity
*Adapt classes which called those objects
*to make delay value configurable
*add default delay value
*remove obsolete method
@martin-v
Copy link
Member Author

Simplest way is to review the resulting source code instead of the commits.


private File repoFolder( final RepositoryHost repoHost, final RepositoryTeam repoTeam,
final RepositoryConfig repoConfig ) {
return new File( new File( new File( workspace, repoHost.getUrl().getHost() ), repoTeam.getName() ),

Choose a reason for hiding this comment

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

You could use org.apache.commons.io.FileUtils#getFile to combine sub-paths

Copy link
Member Author

Choose a reason for hiding this comment

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

done


private static String repoUrl( final RepositoryHost repoHost, final RepositoryTeam repoTeam,
final RepositoryConfig repoConfig ) {
return repoHost.getUrl() + "/" + repoTeam.getName() + "/" + repoConfig.getName() + ".git";

Choose a reason for hiding this comment

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

Is the repo url setup always the same for every service? Otherwise it would be some task for the RepositoryConnector.

Copy link
Member Author

Choose a reason for hiding this comment

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

For currently supported they are the same and also for GitLab, we can change this when needed some time in future.

}

public static List<PullRequest> parsePullRequestsJson( final DocumentContext jsonPath ) {
final int numPullRequests = (int) jsonPath.read( "$.size" );

Choose a reason for hiding this comment

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

Cast is not needed here, since read is generic.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@Override
public PullRequest getLatestUpdate( final PullRequest pullRequest ) {
final DocumentContext jsonPath = jsonPathForPath( requestPath( pullRequest ) );
final PullRequest updatedPullRequest = PullRequest.builder() //

Choose a reason for hiding this comment

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

This can be inline.

final List<Integer> pullRequestAmount = jsonPath.read( "$..number" );
final int numPullRequests = pullRequestAmount.size();
final List<PullRequest> results = new ArrayList<>( numPullRequests );
for ( int i = 0; i < numPullRequests; i++ ) {

Choose a reason for hiding this comment

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

You could use a IntStream.range if you like.

Copy link
Member Author

Choose a reason for hiding this comment

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

No but I simplified the code there

final List<String> states = jsonPath.read( "$..state" );
boolean approved = false;
for ( final String state : states ) {
if ( state.equals( "APPROVED" ) ) {

Choose a reason for hiding this comment

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

Besides your lovely if ( a == true ) (simplify) 😛, you are effectively checking the last state in the list. I assume you want to check if all or any are approved?
Streams help here a lot.

Copy link
Member Author

Choose a reason for hiding this comment

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

Jep nice code, I have overlooked this in refactoring ^^

final List<String> commitIds = jsonPath.read( "$..sha" );
final List<String> parentIds = jsonPath.read( "$..parents..sha" );

return parentIds.stream().filter( parent -> commitIds.contains( parent ) ).findFirst()

Choose a reason for hiding this comment

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

We do not have any convention for streams yet, but I prefer each stream operation to be on a separate line for readability. There would be a few streams in here for adjustments.

Choose a reason for hiding this comment

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

Should we use method references at filter?


@Override
public void merge( final PullRequest pullRequest ) {
final String message = String.format( "Merged in %s (pull request #%d) by ReBaZer", pullRequest.getSource(),

Choose a reason for hiding this comment

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

This message now appears twice... .

Copy link
Member Author

Choose a reason for hiding this comment

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

done

public boolean greenBuildExists( final PullRequest pullRequest ) {
final String urlPath = "/commits/" + pullRequest.getSource() + "/status";
final DocumentContext jsonPath = jsonPathForPath( urlPath );
return jsonPath.<List<String>> read( "$.statuses[*].state" ).stream().anyMatch( s -> s.equals( "success" ) );

Choose a reason for hiding this comment

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

You should use success".equals(s) to avoid NPE and then it can be a method reference.

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed, and some other similar cases

@Override
public boolean greenBuildExists( final PullRequest pullRequest ) {
final DocumentContext jsonPath = jsonPathForPath( requestPath( pullRequest ) + "/statuses" );
return jsonPath.<List<String>> read( "$.values[*].state" ).stream().anyMatch( s -> s.equals( "SUCCESSFUL" ) );

Choose a reason for hiding this comment

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

Same as above: "SUCCESSFUL".equals(s)

@diba1013
Copy link

diba1013 commented Jul 30, 2018

Before merging, should we squash everything. Since 76 commits are quite many?

@martin-v martin-v merged commit 0dbc6b6 into master Aug 2, 2018
@martin-v martin-v deleted the feature/github-support branch August 4, 2018 15:59
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants