-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #471 from JoyOfCodingPDX/issue-452/harvest-student…
…-github-id Address #452 by having the Survey program harvest the student's GitHub user name from the git config file. The user name is stored in the student's XML file.
- Loading branch information
Showing
11 changed files
with
195 additions
and
33 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
45 changes: 45 additions & 0 deletions
45
grader/src/main/java/edu/pdx/cs/joy/grader/GitHubUserNameFinder.java
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package edu.pdx.cs.joy.grader; | ||
|
||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
public class GitHubUserNameFinder implements GitConfigParser.Callback { | ||
private String gitHubUserName; | ||
private boolean isInOrigin; | ||
|
||
@Override | ||
public void startCoreSection() { | ||
|
||
} | ||
|
||
@Override | ||
public void property(String name, String value) { | ||
if (name.equals("url") && this.isInOrigin) { | ||
extractGitHubUserNameFrom(value); | ||
} | ||
} | ||
|
||
private void extractGitHubUserNameFrom(String gitUrl) { | ||
Pattern pattern = Pattern.compile("git@github.com:(.*)/.*\\.git"); | ||
Matcher matcher = pattern.matcher(gitUrl); | ||
if (matcher.matches()) { | ||
this.gitHubUserName = matcher.group(1); | ||
} | ||
} | ||
|
||
@Override | ||
public void endSection(String name) { | ||
this.isInOrigin = false; | ||
} | ||
|
||
@Override | ||
public void startRemoteSection(String name) { | ||
if (name.equals("origin")) { | ||
this.isInOrigin = true; | ||
} | ||
} | ||
|
||
public String getGitHubUserName() { | ||
return gitHubUserName; | ||
} | ||
} |
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
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
18 changes: 18 additions & 0 deletions
18
grader/src/test/java/edu/pdx/cs/joy/grader/GitHubUserNameFinderTest.java
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package edu.pdx.cs.joy.grader; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.equalTo; | ||
|
||
public class GitHubUserNameFinderTest { | ||
|
||
@Test | ||
void findGitHubUserName() { | ||
GitHubUserNameFinder finder = new GitHubUserNameFinder(); | ||
finder.startRemoteSection("origin"); | ||
finder.property("url", "git@github.com:JoyOfCodingPDX/JoyOfCoding.git"); | ||
|
||
assertThat(finder.getGitHubUserName(), equalTo("JoyOfCodingPDX")); | ||
} | ||
} |
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
47 changes: 25 additions & 22 deletions
47
grader/src/test/resources/edu/pdx/cs/joy/grader/gitConfig.txt
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 |
---|---|---|
@@ -1,31 +1,34 @@ | ||
[core] | ||
repositoryformatversion = 0 | ||
filemode = true | ||
bare = false | ||
logallrefupdates = true | ||
ignorecase = true | ||
precomposeunicode = true | ||
repositoryformatversion = 0 | ||
filemode = true | ||
bare = false | ||
logallrefupdates = true | ||
ignorecase = true | ||
precomposeunicode = true | ||
[remote "origin"] | ||
url = git@github.com:JoyOfCodingPDX/JoyOfCoding.git | ||
fetch = +refs/heads/*:refs/remotes/origin/* | ||
url = git@github.com:JoyOfCodingPDX/JoyOfCoding.git | ||
fetch = +refs/heads/*:refs/remotes/origin/* | ||
[branch "main"] | ||
remote = origin | ||
merge = refs/heads/main | ||
remote = origin | ||
merge = refs/heads/main | ||
[branch "issue-463/use-LocalDateTime-for-projects"] | ||
remote = origin | ||
merge = refs/heads/issue-463/use-LocalDateTime-for-projects | ||
remote = origin | ||
merge = refs/heads/issue-463/use-LocalDateTime-for-projects | ||
[branch "issue-453/use-newer-github-actions"] | ||
remote = origin | ||
merge = refs/heads/issue-453/use-newer-github-actions | ||
remote = origin | ||
merge = refs/heads/issue-453/use-newer-github-actions | ||
[branch "issue-463/move-snapshot-repository-include-to-top-level-pom"] | ||
remote = origin | ||
merge = refs/heads/issue-463/move-snapshot-repository-include-to-top-level-pom | ||
remote = origin | ||
merge = refs/heads/issue-463/move-snapshot-repository-include-to-top-level-pom | ||
[branch "issue-465/java-22"] | ||
remote = origin | ||
merge = refs/heads/issue-465/java-22 | ||
remote = origin | ||
merge = refs/heads/issue-465/java-22 | ||
[branch "issue-454/http-code-in-stack-trace"] | ||
remote = origin | ||
merge = refs/heads/issue-454/http-code-in-stack-trace | ||
remote = origin | ||
merge = refs/heads/issue-454/http-code-in-stack-trace | ||
[branch "1.1.1-SNAPSHOT"] | ||
remote = origin | ||
merge = refs/heads/1.1.1-SNAPSHOT | ||
remote = origin | ||
merge = refs/heads/1.1.1-SNAPSHOT | ||
[branch "issue-452/harvest-student-github-id"] | ||
remote = origin | ||
merge = refs/heads/issue-452/harvest-student-github-id |