Skip to content

Commit

Permalink
#1199 GithubWebhookEvent.repoNewName() implemented and tested
Browse files Browse the repository at this point in the history
  • Loading branch information
amihaiemil committed Aug 9, 2021
1 parent 34fbb33 commit 96a0dc8
Show file tree
Hide file tree
Showing 10 changed files with 138 additions and 0 deletions.
6 changes: 6 additions & 0 deletions self-api/src/main/java/com/selfxdsd/api/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ public interface Event {
*/
Commit commit();

/**
* New name (simple name, without owner) of the Repo.
* @return String if this event is REPO_ENAMED, null otherwise.
*/
String repoNewName();

/**
* Project where this event occured.
* @return Project.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ public Commit commit() {
);
}

@Override
public String repoNewName() {
return null;
}

@Override
public Project project() {
return project;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ public Commit commit() {
);
}

@Override
public String repoNewName() {
return null;
}

@Override
public Project project() {
return project;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ public Commit commit() {
);
}

@Override
public String repoNewName() {
return null;
}

@Override
public Project project() {
return project;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ public Commit commit() {
return event.commit();
}

@Override
public String repoNewName() {
return event.repoNewName();
}

@Override
public Project project() {
return event.project();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,18 @@ public Commit commit() {
return commit;
}

@Override
public String repoNewName() {
final String repoNewName;
if(Type.REPO_RENAMED.equalsIgnoreCase(this.type())) {
repoNewName = this.event.getJsonObject("repository")
.getString("name");
} else {
repoNewName = null;
}
return repoNewName;
}

@Override
public Project project() {
return project;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,13 @@ public Commit commit() {
return commit;
}

@Override
public String repoNewName() {
throw new UnsupportedOperationException(
"GitLab doesn't support Webhook for REPO_RENAMED!"
);
}

@Override
public Project project() {
return this.project;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,11 @@ public Commit commit() {
return null;
}

@Override
public String repoNewName() {
return null;
}

@Override
public Project project() {
return project;
Expand Down Expand Up @@ -530,6 +535,11 @@ public Commit commit() {
return null;
}

@Override
public String repoNewName() {
return null;
}

@Override
public Project project() {
return project;
Expand Down Expand Up @@ -609,6 +619,11 @@ public Commit commit() {
return null;
}

@Override
public String repoNewName() {
return null;
}

@Override
public Project project() {
return project;
Expand Down Expand Up @@ -690,6 +705,11 @@ public Commit commit() {
return null;
}

@Override
public String repoNewName() {
return null;
}

@Override
public Project project() {
return project;
Expand Down Expand Up @@ -765,6 +785,11 @@ public Commit commit() {
return null;
}

@Override
public String repoNewName() {
return null;
}

@Override
public Project project() {
return project;
Expand Down Expand Up @@ -843,6 +868,11 @@ public Commit commit() {
return null;
}

@Override
public String repoNewName() {
return null;
}

@Override
public Project project() {
return project;
Expand Down Expand Up @@ -923,6 +953,11 @@ public Commit commit() {
return null;
}

@Override
public String repoNewName() {
return null;
}

@Override
public Project project() {
return project;
Expand Down Expand Up @@ -1004,6 +1039,11 @@ public Commit commit() {
return null;
}

@Override
public String repoNewName() {
return null;
}

@Override
public Project project() {
return project;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ public Commit commit() {
return null;
}

@Override
public String repoNewName() {
return null;
}

@Override
public Project project() {
return project;
Expand Down Expand Up @@ -148,6 +153,11 @@ public Commit commit() {
return null;
}

@Override
public String repoNewName() {
return null;
}

@Override
public Project project() {
return project;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,49 @@ public void returnsRepoRenameType() {
);
}

/**
* GithubWebhookEvent can return the repoNewName if the type is
* REPO_RENAMED.
*/
@Test
public void returnsRepoNewNameIfTypeRenamed() {
final Project project = Mockito.mock(Project.class);
final Event event = new GithubWebhookEvent(
project,
"repository",
Json.createObjectBuilder()
.add("action", "renamed")
.add(
"repository",
Json.createObjectBuilder()
.add("name", "new_name")
.build()
).build().toString()
);
MatcherAssert.assertThat(
event.repoNewName(),
Matchers.equalTo("new_name")
);
}

/**
* GithubWebhookEvent returns null repoNewName if type is not REPO_RENAMED.
*/
@Test
public void returnsNullRepoNewNameIfTypeNotRenamed() {
final Project project = Mockito.mock(Project.class);
final Event event = new GithubWebhookEvent(
project,
"repository",
Json.createObjectBuilder()
.add("action", "publicised")
.build().toString()
);
MatcherAssert.assertThat(
event.repoNewName(),
Matchers.nullValue()
);
}

/**
* GithubWebhookEvent can return the newIssue PR type.
Expand Down

0 comments on commit 96a0dc8

Please sign in to comment.