Skip to content

Commit 3a96fd4

Browse files
author
craigsdennis
committed
Moves the GitHub bootstrap to be form based instead of application based
1 parent caaf74e commit 3a96fd4

File tree

4 files changed

+58
-22
lines changed

4 files changed

+58
-22
lines changed

src/main/java/com/teamtreehouse/flashy/controllers/BootstrapController.java

+20-15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.teamtreehouse.flashy.controllers;
22

3+
import com.teamtreehouse.flashy.domain.BootstrapOptions;
4+
35
import org.eclipse.egit.github.core.Issue;
46
import org.eclipse.egit.github.core.Repository;
57
import org.eclipse.egit.github.core.User;
@@ -8,11 +10,11 @@
810
import org.eclipse.egit.github.core.service.IssueService;
911
import org.eclipse.egit.github.core.service.RepositoryService;
1012
import org.eclipse.egit.github.core.service.UserService;
11-
import org.springframework.beans.factory.annotation.Value;
1213
import org.springframework.stereotype.Controller;
1314
import org.springframework.ui.Model;
15+
import org.springframework.web.bind.annotation.ModelAttribute;
1416
import org.springframework.web.bind.annotation.RequestMapping;
15-
import org.springframework.web.bind.annotation.RequestParam;
17+
import org.springframework.web.bind.annotation.RequestMethod;
1618

1719
import java.io.IOException;
1820
import java.util.ArrayList;
@@ -23,7 +25,6 @@
2325

2426
@Controller
2527
public 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
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.teamtreehouse.flashy.domain;
2+
3+
public class BootstrapOptions {
4+
private boolean shouldFork;
5+
private String githubOauth;
6+
7+
public boolean isShouldFork() {
8+
return shouldFork;
9+
}
10+
11+
public void setShouldFork(boolean shouldFork) {
12+
this.shouldFork = shouldFork;
13+
}
14+
15+
public String getGithubOauth() {
16+
return githubOauth;
17+
}
18+
19+
public void setGithubOauth(String githubOauth) {
20+
this.githubOauth = githubOauth;
21+
}
22+
}

src/main/resources/application.properties

-1
This file was deleted.

src/main/resources/templates/bootstrap_github.html

+16-6
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,34 @@
1212
<div class="bounds">
1313
<div class="card">
1414
<h1 class="logo">GitHub Bootstrap</h1>
15-
<div th:if="${configNeedsUpdate}" style="text-align: left">
15+
<div th:unless="${options.githubOauth}" style="text-align: left">
1616
<p>In order to copy issues across you need to create a <a href="https://github.com/settings/tokens" target="_blank">GitHub personal access token</a>.</p>
1717
<p>On that page, choose "Generate new token".
1818
<ol>
1919
<li>Name it something like "Treehouse Issue Copier"</li>
2020
<li>Check the repo scope. (The first one).</li>
2121
<li>Click Generate token.</li>
2222
<li>Copy the token to your clipboard</li>
23-
<li>Replace "YOUR-TOKEN-HERE" in the <code>resources/application.properties</code> file.</li>
23+
<li>Paste it in the box below:</li>
2424
</ol>
2525
</p>
26+
<form action="#" th:action="@{/bootstrap/github}" th:object="${options}" method="post">
27+
<div>
28+
<input type="text" placeholder="Enter your GitHub oauth token here" th:field="*{githubOauth}" size="50"/>
29+
</div>
30+
<input type="submit" value="Submit" class="button button-primary"/>
31+
</form>
2632
</div>
27-
<div th:unless="${configNeedsUpdate}">
28-
<div th:unless="${shouldFork}">
33+
<div th:if="${options.githubOauth}">
34+
<div th:unless="${options.shouldFork}">
2935
<p>Are you ready to fork the <code th:text="${repoName}"></code> and its issues to your <code th:text="${gitHubUserName}"></code> GitHub Account</p>
30-
<a href="/bootstrap/github?forkIt=true">Fork it!</a>
36+
<form action="#" th:action="@{/bootstrap/github}" th:object="${options}" method="post">
37+
<input type="hidden" th:field="*{githubOauth}" />
38+
<input type="hidden" id="shouldFork" name="shouldFork" th:value="true" />
39+
<input type="submit" value="Fork it!" class="button button-primary"/>
40+
</form>
3141
</div>
32-
<div th:if="${shouldFork}" style="text-align: left">
42+
<div th:if="${options.shouldFork}" style="text-align: left">
3343
<h2>Success!</h2>
3444
<p>The following actions were performed:
3545
<ul>

0 commit comments

Comments
 (0)