Skip to content
This repository has been archived by the owner on Dec 18, 2018. It is now read-only.

Commit

Permalink
Project.hook() Github endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
amihaiemil committed Jun 6, 2017
1 parent e410c10 commit 5ab3b3e
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/main/java/com/amihaiemil/versioneye/Github.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
* @author Sherif Waly (sherifwaly95@gmail.com)
* @version $Id$
* @since 1.0.0
* @todo #89:30min/DEV Complete Github API methods.
* @todo #101:30min/DEV Complete Github API methods. When possible,
* think that you can implement those methods on a Project.
* (e.g. see Project.hook()).
*/
public interface Github {

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/amihaiemil/versioneye/Organizations.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,6 @@ public interface Organizations {
* Get the original VersionEye instance.
* @return VersionEye
*/
VersionEye versionEye();
RtVersionEye versionEye();

}
8 changes: 8 additions & 0 deletions src/main/java/com/amihaiemil/versioneye/Project.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,12 @@ public interface Project {
*/
@Deprecated
Project update(File projectFile) throws IOException;

/**
* Create a Github webhook to re-parse this project at
* each git push.
* @return This Project.
* @throws IOException If something goes wrong with the HTTP call.
*/
Project hook() throws IOException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public Organization organization(final String organizationName)
}

@Override
public VersionEye versionEye() {
public RtVersionEye versionEye() {
return this.versionEye;
}

Expand Down
14 changes: 14 additions & 0 deletions src/main/java/com/amihaiemil/versioneye/RtProject.java
Original file line number Diff line number Diff line change
Expand Up @@ -194,4 +194,18 @@ public JsonObject json() {
return this.project;
}

@Override
public Project hook() throws IOException {
this.team.versionEye()
.request().uri()
.path("/github/hook/")
.path(this.projectId())
.back()
.method("POST")
.fetch()
.as(RestResponse.class)
.assertStatus(HttpURLConnection.HTTP_CREATED);
return this;
}

}
2 changes: 1 addition & 1 deletion src/main/java/com/amihaiemil/versioneye/RtTeam.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public Organization organization() {
}

@Override
public VersionEye versionEye() {
public RtVersionEye versionEye() {
return this.versionEye;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/amihaiemil/versioneye/RtTeams.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public Organization organization() {
}

@Override
public VersionEye versionEye() {
public RtVersionEye versionEye() {
return this.versionEye;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/amihaiemil/versioneye/Team.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public interface Team {
* Get the initial VersionEye instance.
* @return VersionEye.
*/
VersionEye versionEye();
RtVersionEye versionEye();

/**
* Members of this team.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/amihaiemil/versioneye/Teams.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,5 @@ public interface Teams {
* Get the initial VersionEye instance.
* @return VersionEye.
*/
VersionEye versionEye();
RtVersionEye versionEye();
}
30 changes: 30 additions & 0 deletions src/test/java/com/amihaiemil/versioneye/RtProjectTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -304,4 +304,34 @@ public void deletesProject() throws IOException {
request.uri().toString(), Matchers.equalTo("/project123")
);
}

/**
* RtProject can hook itself to Github.
* @throws IOException If something goes wrong.
*/
@Test
public void hooksOnGithub() throws IOException {
final MkContainer container = new MkGrizzlyContainer().next(
new MkAnswer.Simple(HttpURLConnection.HTTP_CREATED)
).start();
Team team = Mockito.mock(Team.class);
Mockito.when(team.versionEye())
.thenReturn(
new RtVersionEye(
new JdkRequest(container.home())
)
);
final Project project = new RtProject(
new FakeRequest(), team,
Json.createObjectBuilder().add("ids", "id123").build()
);
MatcherAssert.assertThat(project.hook(), Matchers.is(project));
final MkQuery request = container.take();
MatcherAssert.assertThat(
request.method(), Matchers.equalTo("POST")
);
MatcherAssert.assertThat(
request.uri().toString(), Matchers.equalTo("/github/hook/id123")
);
}
}

0 comments on commit 5ab3b3e

Please sign in to comment.