11package com .teamtreehouse .flashy .controllers ;
22
3+ import com .teamtreehouse .flashy .domain .BootstrapOptions ;
4+
35import org .eclipse .egit .github .core .Issue ;
46import org .eclipse .egit .github .core .Repository ;
57import org .eclipse .egit .github .core .User ;
810import org .eclipse .egit .github .core .service .IssueService ;
911import org .eclipse .egit .github .core .service .RepositoryService ;
1012import org .eclipse .egit .github .core .service .UserService ;
11- import org .springframework .beans .factory .annotation .Value ;
1213import org .springframework .stereotype .Controller ;
1314import org .springframework .ui .Model ;
15+ import org .springframework .web .bind .annotation .ModelAttribute ;
1416import org .springframework .web .bind .annotation .RequestMapping ;
15- import org .springframework .web .bind .annotation .RequestParam ;
17+ import org .springframework .web .bind .annotation .RequestMethod ;
1618
1719import java .io .IOException ;
1820import java .util .ArrayList ;
2325
2426@ Controller
2527public class BootstrapController {
26- private final String DEFAULT_TOKEN = "YOUR-TOKEN-HERE" ;
2728 private final String GITHUB_MASTER_REPO_OWNER = "treehouse-projects" ;
2829 private final String GITHUB_MASTER_REPO_NAME = "java-debugging-flashy" ;
2930
@@ -43,23 +44,26 @@ public List<String> getActions() {
4344 }
4445 }
4546
46- @ Value ("${github.oauth.token}" )
4747 private String oauthToken ;
4848
49- @ RequestMapping ("/bootstrap/github" )
50- public String setupGitHub (@ RequestParam (value = "forkIt" , defaultValue = "false" ) boolean forkIt , Model model ) {
49+ @ RequestMapping (value = "/bootstrap/github" , method = RequestMethod .GET )
50+ public String promptForGitHub (Model model ) {
51+ model .addAttribute ("options" , new BootstrapOptions ());
52+ return "bootstrap_github" ;
53+ }
54+
55+ @ RequestMapping (value = "/bootstrap/github" , method = RequestMethod .POST )
56+ public String forkIt (@ ModelAttribute BootstrapOptions options , Model model ) {
57+ model .addAttribute ("options" , options );
58+ oauthToken = options .getGithubOauth ();
5159 WorkLog workLog = new WorkLog ();
5260 try {
53- boolean configNeedsUpdate = oauthToken .equals (DEFAULT_TOKEN );
54- model .addAttribute ("configNeedsUpdate" , configNeedsUpdate );
55- model .addAttribute ("shouldFork" , forkIt );
5661 model .addAttribute ("repoName" , GITHUB_MASTER_REPO_NAME );
57- if (! configNeedsUpdate ) {
58- String userName = getGitHubUserName ();
62+ String userName = getGitHubUserName ();
63+ if (! options . isShouldFork ()) {
5964 model .addAttribute ("gitHubUserName" , userName );
60- if (forkIt ) {
61- bootstrapRepo (workLog , userName );
62- }
65+ } else {
66+ bootstrapRepo (workLog , userName );
6367 }
6468 } catch (IOException e ) {
6569 e .printStackTrace ();
@@ -104,10 +108,11 @@ public void bootstrapRepo(WorkLog workLog, String gitHubUserName) throws IOExcep
104108 for (Issue issue : issues ) {
105109 if (!existingIssueTitles .contains (issue .getTitle ())) {
106110 issueService .createIssue (gitHubUserName , GITHUB_MASTER_REPO_NAME , issue );
111+ workLog .track ("Added issue '%s'" , issue .getTitle ());
107112 issueCount ++;
108113 }
109114 }
110115 }
111- workLog .track ("Created %d issues in your repoository" , issueCount );
116+ workLog .track ("Created %d new issues in your repoository" , issueCount );
112117 }
113118}
0 commit comments