1
1
package com .teamtreehouse .flashy .controllers ;
2
2
3
+ import com .teamtreehouse .flashy .domain .BootstrapOptions ;
4
+
3
5
import org .eclipse .egit .github .core .Issue ;
4
6
import org .eclipse .egit .github .core .Repository ;
5
7
import org .eclipse .egit .github .core .User ;
8
10
import org .eclipse .egit .github .core .service .IssueService ;
9
11
import org .eclipse .egit .github .core .service .RepositoryService ;
10
12
import org .eclipse .egit .github .core .service .UserService ;
11
- import org .springframework .beans .factory .annotation .Value ;
12
13
import org .springframework .stereotype .Controller ;
13
14
import org .springframework .ui .Model ;
15
+ import org .springframework .web .bind .annotation .ModelAttribute ;
14
16
import org .springframework .web .bind .annotation .RequestMapping ;
15
- import org .springframework .web .bind .annotation .RequestParam ;
17
+ import org .springframework .web .bind .annotation .RequestMethod ;
16
18
17
19
import java .io .IOException ;
18
20
import java .util .ArrayList ;
23
25
24
26
@ Controller
25
27
public class BootstrapController {
26
- private final String DEFAULT_TOKEN = "YOUR-TOKEN-HERE" ;
27
28
private final String GITHUB_MASTER_REPO_OWNER = "treehouse-projects" ;
28
29
private final String GITHUB_MASTER_REPO_NAME = "java-debugging-flashy" ;
29
30
@@ -43,23 +44,26 @@ public List<String> getActions() {
43
44
}
44
45
}
45
46
46
- @ Value ("${github.oauth.token}" )
47
47
private String oauthToken ;
48
48
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 ();
51
59
WorkLog workLog = new WorkLog ();
52
60
try {
53
- boolean configNeedsUpdate = oauthToken .equals (DEFAULT_TOKEN );
54
- model .addAttribute ("configNeedsUpdate" , configNeedsUpdate );
55
- model .addAttribute ("shouldFork" , forkIt );
56
61
model .addAttribute ("repoName" , GITHUB_MASTER_REPO_NAME );
57
- if (! configNeedsUpdate ) {
58
- String userName = getGitHubUserName ();
62
+ String userName = getGitHubUserName ();
63
+ if (! options . isShouldFork ()) {
59
64
model .addAttribute ("gitHubUserName" , userName );
60
- if (forkIt ) {
61
- bootstrapRepo (workLog , userName );
62
- }
65
+ } else {
66
+ bootstrapRepo (workLog , userName );
63
67
}
64
68
} catch (IOException e ) {
65
69
e .printStackTrace ();
@@ -104,10 +108,11 @@ public void bootstrapRepo(WorkLog workLog, String gitHubUserName) throws IOExcep
104
108
for (Issue issue : issues ) {
105
109
if (!existingIssueTitles .contains (issue .getTitle ())) {
106
110
issueService .createIssue (gitHubUserName , GITHUB_MASTER_REPO_NAME , issue );
111
+ workLog .track ("Added issue '%s'" , issue .getTitle ());
107
112
issueCount ++;
108
113
}
109
114
}
110
115
}
111
- workLog .track ("Created %d issues in your repoository" , issueCount );
116
+ workLog .track ("Created %d new issues in your repoository" , issueCount );
112
117
}
113
118
}
0 commit comments