Skip to content

Commit

Permalink
Moves the GitHub bootstrap to be form based instead of application based
Browse files Browse the repository at this point in the history
  • Loading branch information
craigsdennis committed Jul 12, 2016
1 parent caaf74e commit 3a96fd4
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.teamtreehouse.flashy.controllers;

import com.teamtreehouse.flashy.domain.BootstrapOptions;

import org.eclipse.egit.github.core.Issue;
import org.eclipse.egit.github.core.Repository;
import org.eclipse.egit.github.core.User;
Expand All @@ -8,11 +10,11 @@
import org.eclipse.egit.github.core.service.IssueService;
import org.eclipse.egit.github.core.service.RepositoryService;
import org.eclipse.egit.github.core.service.UserService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestMethod;

import java.io.IOException;
import java.util.ArrayList;
Expand All @@ -23,7 +25,6 @@

@Controller
public class BootstrapController {
private final String DEFAULT_TOKEN = "YOUR-TOKEN-HERE";
private final String GITHUB_MASTER_REPO_OWNER = "treehouse-projects";
private final String GITHUB_MASTER_REPO_NAME = "java-debugging-flashy";

Expand All @@ -43,23 +44,26 @@ public List<String> getActions() {
}
}

@Value("${github.oauth.token}")
private String oauthToken;

@RequestMapping("/bootstrap/github")
public String setupGitHub(@RequestParam(value = "forkIt", defaultValue = "false") boolean forkIt, Model model) {
@RequestMapping(value = "/bootstrap/github", method = RequestMethod.GET)
public String promptForGitHub(Model model) {
model.addAttribute("options", new BootstrapOptions());
return "bootstrap_github";
}

@RequestMapping(value = "/bootstrap/github", method = RequestMethod.POST)
public String forkIt(@ModelAttribute BootstrapOptions options, Model model) {
model.addAttribute("options", options);
oauthToken = options.getGithubOauth();
WorkLog workLog = new WorkLog();
try {
boolean configNeedsUpdate = oauthToken.equals(DEFAULT_TOKEN);
model.addAttribute("configNeedsUpdate", configNeedsUpdate);
model.addAttribute("shouldFork", forkIt);
model.addAttribute("repoName", GITHUB_MASTER_REPO_NAME);
if (!configNeedsUpdate) {
String userName = getGitHubUserName();
String userName = getGitHubUserName();
if (!options.isShouldFork()) {
model.addAttribute("gitHubUserName", userName);
if (forkIt) {
bootstrapRepo(workLog, userName);
}
} else {
bootstrapRepo(workLog, userName);
}
} catch (IOException e) {
e.printStackTrace();
Expand Down Expand Up @@ -104,10 +108,11 @@ public void bootstrapRepo(WorkLog workLog, String gitHubUserName) throws IOExcep
for (Issue issue : issues) {
if (!existingIssueTitles.contains(issue.getTitle())) {
issueService.createIssue(gitHubUserName, GITHUB_MASTER_REPO_NAME, issue);
workLog.track("Added issue '%s'", issue.getTitle());
issueCount++;
}
}
}
workLog.track("Created %d issues in your repoository", issueCount);
workLog.track("Created %d new issues in your repoository", issueCount);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.teamtreehouse.flashy.domain;

public class BootstrapOptions {
private boolean shouldFork;
private String githubOauth;

public boolean isShouldFork() {
return shouldFork;
}

public void setShouldFork(boolean shouldFork) {
this.shouldFork = shouldFork;
}

public String getGithubOauth() {
return githubOauth;
}

public void setGithubOauth(String githubOauth) {
this.githubOauth = githubOauth;
}
}
1 change: 0 additions & 1 deletion src/main/resources/application.properties

This file was deleted.

22 changes: 16 additions & 6 deletions src/main/resources/templates/bootstrap_github.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,34 @@
<div class="bounds">
<div class="card">
<h1 class="logo">GitHub Bootstrap</h1>
<div th:if="${configNeedsUpdate}" style="text-align: left">
<div th:unless="${options.githubOauth}" style="text-align: left">
<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>
<p>On that page, choose "Generate new token".
<ol>
<li>Name it something like "Treehouse Issue Copier"</li>
<li>Check the repo scope. (The first one).</li>
<li>Click Generate token.</li>
<li>Copy the token to your clipboard</li>
<li>Replace "YOUR-TOKEN-HERE" in the <code>resources/application.properties</code> file.</li>
<li>Paste it in the box below:</li>
</ol>
</p>
<form action="#" th:action="@{/bootstrap/github}" th:object="${options}" method="post">
<div>
<input type="text" placeholder="Enter your GitHub oauth token here" th:field="*{githubOauth}" size="50"/>
</div>
<input type="submit" value="Submit" class="button button-primary"/>
</form>
</div>
<div th:unless="${configNeedsUpdate}">
<div th:unless="${shouldFork}">
<div th:if="${options.githubOauth}">
<div th:unless="${options.shouldFork}">
<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>
<a href="/bootstrap/github?forkIt=true">Fork it!</a>
<form action="#" th:action="@{/bootstrap/github}" th:object="${options}" method="post">
<input type="hidden" th:field="*{githubOauth}" />
<input type="hidden" id="shouldFork" name="shouldFork" th:value="true" />
<input type="submit" value="Fork it!" class="button button-primary"/>
</form>
</div>
<div th:if="${shouldFork}" style="text-align: left">
<div th:if="${options.shouldFork}" style="text-align: left">
<h2>Success!</h2>
<p>The following actions were performed:
<ul>
Expand Down

0 comments on commit 3a96fd4

Please sign in to comment.