Skip to content

Commit

Permalink
Merge pull request #70 from criske/#69
Browse files Browse the repository at this point in the history
#69 Fixed bug where latest commit was fetched unauthenticated.
  • Loading branch information
amihaiemil authored Sep 6, 2021
2 parents 33dadff + 0af9fab commit 43e2587
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 9 deletions.
11 changes: 9 additions & 2 deletions src/main/java/com/selfxdsd/todos/JsonPuzzles.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,16 @@ public void process(final String input) throws PuzzlesProcessingException {
.setEmail("")
.setRole("DEV");
for (final JsonValue jsonValue : jsonArray) {
JsonObject jsonObject = jsonValue.asJsonObject();
final JsonObject jsonObject = jsonValue.asJsonObject();
final String[] fullNameSplit = this.project.repoFullName()
.split("/");
builder
.setCommit(this.project.repo().commits().latest())
.setCommit(this.project
.projectManager()
.provider()
.repo(fullNameSplit[0], fullNameSplit[1])
.commits()
.latest())
.setId(Integer.toString(jsonObject.getInt("id")))
.setStart(jsonObject.getInt("start"))
.setEnd(jsonObject.getInt("end"))
Expand Down
44 changes: 37 additions & 7 deletions src/test/java/com/selfxdsd/todos/JsonPuzzlesTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ public void canParsePuzzlesFromJson() throws PuzzlesProcessingException {
final Repo repo = Mockito.mock(Repo.class);
Mockito.when(repo.commits()).thenReturn(commits);
final Project project = Mockito.mock(Project.class);
Mockito.when(project.repo()).thenReturn(repo);
final ProjectManager manager = Mockito.mock(ProjectManager.class);
final Provider provider = Mockito.mock(Provider.class);
Mockito.when(manager.provider()).thenReturn(provider);
Mockito.when(provider.repo("john", "test"))
.thenReturn(repo);
Mockito.when(project.projectManager()).thenReturn(manager);
Mockito.when(project.repoFullName()).thenReturn("john/test");

final Puzzles<String> puzzles = new ResourcesPuzzles(
new JsonPuzzles(
Expand Down Expand Up @@ -83,7 +89,13 @@ public void printsGithubIssueBody() throws PuzzlesProcessingException {
Mockito.when(repo.commits()).thenReturn(commits);
final Project project = Mockito.mock(Project.class);
Mockito.when(project.provider()).thenReturn(Provider.Names.GITHUB);
Mockito.when(project.repo()).thenReturn(repo);
final ProjectManager manager = Mockito.mock(ProjectManager.class);
final Provider provider = Mockito.mock(Provider.class);
Mockito.when(manager.provider()).thenReturn(provider);
Mockito.when(provider.repo("john", "test"))
.thenReturn(repo);
Mockito.when(project.projectManager()).thenReturn(manager);
Mockito.when(project.repoFullName()).thenReturn("john/test");

final Puzzles<String> puzzles = new ResourcesPuzzles(
new JsonPuzzles(
Expand All @@ -100,7 +112,7 @@ public void printsGithubIssueBody() throws PuzzlesProcessingException {
puzzle.issueBody(),
Matchers.equalTo(
"The puzzle ``1194770182`` originating from #153 has to be resolved:\n\n"
+ "https://github.com/null/blob/null/.\\RtImagesITCase.java#L42-L42\n\n"
+ "https://github.com/john/test/blob/null/.\\RtImagesITCase.java#L42-L42\n\n"
+ "\"Add integration tests for filters.\".\n\n\n"
+ "The puzzle was created by amihaiemil at ``2020-11-08 20:19:56 +0100``. \n"
+ "Estimation is ``30 minutes``.\n"
Expand All @@ -123,7 +135,13 @@ public void printsGitLabIssueBody() throws PuzzlesProcessingException {
Mockito.when(repo.commits()).thenReturn(commits);
final Project project = Mockito.mock(Project.class);
Mockito.when(project.provider()).thenReturn(Provider.Names.GITLAB);
Mockito.when(project.repo()).thenReturn(repo);
final ProjectManager manager = Mockito.mock(ProjectManager.class);
final Provider provider = Mockito.mock(Provider.class);
Mockito.when(manager.provider()).thenReturn(provider);
Mockito.when(provider.repo("john", "test"))
.thenReturn(repo);
Mockito.when(project.projectManager()).thenReturn(manager);
Mockito.when(project.repoFullName()).thenReturn("john/test");

final Puzzles<String> puzzles = new ResourcesPuzzles(
new JsonPuzzles(
Expand Down Expand Up @@ -164,7 +182,13 @@ public void printsGithubIssueBodyWithoutAuthor() throws PuzzlesProcessingExcepti
Mockito.when(repo.commits()).thenReturn(commits);
final Project project = Mockito.mock(Project.class);
Mockito.when(project.provider()).thenReturn(Provider.Names.GITHUB);
Mockito.when(project.repo()).thenReturn(repo);
final ProjectManager manager = Mockito.mock(ProjectManager.class);
final Provider provider = Mockito.mock(Provider.class);
Mockito.when(manager.provider()).thenReturn(provider);
Mockito.when(provider.repo("john", "test"))
.thenReturn(repo);
Mockito.when(project.projectManager()).thenReturn(manager);
Mockito.when(project.repoFullName()).thenReturn("john/test");

final Puzzles<String> puzzles = new ResourcesPuzzles(
new JsonPuzzles(
Expand All @@ -183,7 +207,7 @@ public void printsGithubIssueBodyWithoutAuthor() throws PuzzlesProcessingExcepti
puzzle.issueBody(),
Matchers.equalTo(
"The puzzle ``-1377131499`` originating from #187 has to be resolved:\n\n"
+ "https://github.com/null/blob/null/.\\RtImagesITCase.java#L69-L72\n\n"
+ "https://github.com/john/test/blob/null/.\\RtImagesITCase.java#L69-L72\n\n"
+ "\"Add integration tests for filters.\".\n\n\n"
+ "Estimation is ``30 minutes``.\n"
+ "If you have any technical questions, don't ask me, I won't be able to help. Open new issues instead."
Expand All @@ -205,7 +229,13 @@ public void printsGitLabIssueBodyWithoutAuthor() throws PuzzlesProcessingExcepti
Mockito.when(repo.commits()).thenReturn(commits);
final Project project = Mockito.mock(Project.class);
Mockito.when(project.provider()).thenReturn(Provider.Names.GITLAB);
Mockito.when(project.repo()).thenReturn(repo);
final ProjectManager manager = Mockito.mock(ProjectManager.class);
final Provider provider = Mockito.mock(Provider.class);
Mockito.when(manager.provider()).thenReturn(provider);
Mockito.when(provider.repo("john", "test"))
.thenReturn(repo);
Mockito.when(project.projectManager()).thenReturn(manager);
Mockito.when(project.repoFullName()).thenReturn("john/test");

final Puzzles<String> puzzles = new ResourcesPuzzles(
new JsonPuzzles(
Expand Down

0 comments on commit 43e2587

Please sign in to comment.