This repository has been archived by the owner on Dec 5, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
180 additions
and
37 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
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 |
---|---|---|
|
@@ -26,7 +26,6 @@ | |
package com.amihaiemil.charles.github; | ||
|
||
import org.slf4j.Logger; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
|
@@ -40,48 +39,91 @@ | |
* @author Mihai Andronache ([email protected]) | ||
* @version $Id$ | ||
* @since 1.0.1 | ||
* @todo #219:1h Write some integration tests for this step, check that | ||
* the tree of steps executes correctly/in the right order. For this, you | ||
* need to mock a Github server (use MkGithub) in appropriate ways, to check | ||
* each flow. | ||
*/ | ||
public final class GeneralPreconditionsCheck extends PreconditionCheckStep { | ||
public final class GeneralPreconditionsCheck extends IntermediaryStep { | ||
|
||
/** | ||
* .charles.yml config file. | ||
* Ctor. | ||
* @param next Next step, after all precondition have passed. | ||
*/ | ||
private CharlesYml charlesYml; | ||
public GeneralPreconditionsCheck(final Step next) { | ||
super(next); | ||
} | ||
|
||
@Override | ||
public void perform(Command command, Logger logger) throws IOException { | ||
final PreconditionCheckStep all; | ||
|
||
final PreconditionCheckStep repoForkCheck = new RepoForkCheck( | ||
command.repo().json(), this.next(), | ||
this.finalCommentStep(command, "denied.fork.comment", command.authorLogin()) | ||
); | ||
|
||
if(!this.isCommanderAllowed(command)) { | ||
final PreconditionCheckStep authorOwnerCheck = new AuthorOwnerCheck( | ||
repoForkCheck, | ||
new OrganizationAdminCheck( | ||
repoForkCheck, | ||
this.finalCommentStep(command, "denied.commander.comment", command.authorLogin()) | ||
) | ||
); | ||
all = new RepoNameCheck( | ||
command.repo().json(), authorOwnerCheck, | ||
new GhPagesBranchCheck( | ||
authorOwnerCheck, | ||
this.finalCommentStep(command, "denied.name.comment", command.authorLogin()) | ||
) | ||
); | ||
} else { | ||
all = new RepoNameCheck( | ||
command.repo().json(), repoForkCheck, | ||
new GhPagesBranchCheck( | ||
repoForkCheck, | ||
this.finalCommentStep(command, "denied.name.comment", command.authorLogin()) | ||
) | ||
); | ||
} | ||
all.perform(command, logger); | ||
} | ||
|
||
/** | ||
* Ctor. | ||
* @param onTrue Step that should be performed next if the check is true. | ||
* @param onFalse Step that should be performed next if the check is false. | ||
* @param charlesYml This is the .charles.yml config file. | ||
* Builds the final comment to be sent to the issue. | ||
* <b>This should be the last in the steps' chain</b>. | ||
* @param com Command. | ||
* @param formatParts Parts to format the response %s elements with. | ||
* @return SendReply step. | ||
*/ | ||
public GeneralPreconditionsCheck( | ||
final Step onTrue, | ||
final Step onFalse, | ||
final CharlesYml charlesYml | ||
private SendReply finalCommentStep( | ||
Command com, String messagekey, String ... formatParts | ||
) { | ||
super(onTrue, onFalse); | ||
this.charlesYml = charlesYml; | ||
return new SendReply( | ||
new TextReply( | ||
com, | ||
String.format( | ||
com.language().response(messagekey), | ||
(Object[]) formatParts | ||
) | ||
), | ||
new Step.FinalStep() | ||
); | ||
} | ||
|
||
@Override | ||
public void perform(Command command, Logger logger) throws IOException { | ||
// PreconditionCheckStep repoForkCheck = new RepoForkCheck( | ||
// command.repo().json(), action, | ||
// this.finalCommentStep(command, lang, "denied.fork.comment", command.authorLogin()) | ||
// ); | ||
// PreconditionCheckStep authorOwnerCheck = new AuthorOwnerCheck( | ||
// repoForkCheck, | ||
// new OrganizationAdminCheck( | ||
// repoForkCheck, | ||
// this.finalCommentStep(command, lang, "denied.commander.comment", command.authorLogin()) | ||
// ) | ||
// ); | ||
// PreconditionCheckStep repoNameCheck = new RepoNameCheck( | ||
// command.repo().json(), authorOwnerCheck, | ||
// new GhPagesBranchCheck( | ||
// authorOwnerCheck, | ||
// this.finalCommentStep(command, lang, "denied.name.comment", command.authorLogin()) | ||
// ) | ||
// ); | ||
/** | ||
* Is the command's author specified in .charles.yml as a commander? | ||
* @param com Initial command. | ||
* @throws IOException if the commanders' list cannot be read from Github. | ||
* @return True of False | ||
*/ | ||
private boolean isCommanderAllowed(Command com) throws IOException { | ||
for(String commander : com.repo().charlesYml().commanders()) { | ||
if(commander.equalsIgnoreCase(com.authorLogin())) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
} |
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
ae5026b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Puzzle
219-dd617bae
discovered insrc/main/java/com/amihaiemil/charles/github/GeneralPreconditionsCheck.java
and submitted as #234.