Expose repository for artifacts, workflows and workflow runs

This commit is contained in:
Guillaume Smet
2021-04-03 20:54:31 +02:00
parent f40daf8488
commit 97652c6803
5 changed files with 32 additions and 0 deletions

View File

@@ -73,6 +73,15 @@ public class GHArtifact extends GHObject {
return GitHubClient.parseDate(expiresAt);
}
/**
* Repository to which the artifact belongs.
*
* @return the repository
*/
public GHRepository getRepository() {
return owner;
}
/**
* @deprecated This object has no HTML URL.
*/

View File

@@ -60,6 +60,15 @@ public class GHWorkflow extends GHObject {
return GitHubClient.parseURL(htmlUrl);
}
/**
* Repository to which the workflow belongs.
*
* @return the repository
*/
public GHRepository getRepository() {
return owner;
}
/**
* The badge URL, like https://github.com/octo-org/octo-repo/workflows/CI/badge.svg
*

View File

@@ -213,6 +213,15 @@ public class GHWorkflowRun extends GHObject {
return Conclusion.from(conclusion);
}
/**
* Repository to which the workflow run belongs.
*
* @return the repository
*/
public GHRepository getRepository() {
return owner;
}
/**
* Gets the pull requests participated in this workflow run.
*

View File

@@ -62,6 +62,9 @@ public class GHWorkflowRunTest extends AbstractGitHubWireMockTest {
() -> new IllegalStateException("We must have a valid workflow run starting from here"));
assertEquals(workflow.getId(), workflowRun.getWorkflowId());
assertNotNull(workflowRun.getId());
assertNotNull(workflowRun.getNodeId());
assertEquals(REPO_NAME, workflowRun.getRepository().getFullName());
assertTrue(workflowRun.getUrl().getPath().contains("/actions/runs/"));
assertTrue(workflowRun.getHtmlUrl().getPath().contains("/actions/runs/"));
assertTrue(workflowRun.getJobsUrl().getPath().endsWith("/jobs"));
@@ -379,6 +382,7 @@ public class GHWorkflowRunTest extends AbstractGitHubWireMockTest {
private static void checkArtifactProperties(GHArtifact artifact, String artifactName) throws IOException {
assertNotNull(artifact.getId());
assertNotNull(artifact.getNodeId());
assertEquals(REPO_NAME, artifact.getRepository().getFullName());
assertThat(artifact.getName(), is(artifactName));
assertThat(artifact.getArchiveDownloadUrl().getPath(), containsString("actions/artifacts"));
assertNotNull(artifact.getCreatedAt());

View File

@@ -43,6 +43,7 @@ public class GHWorkflowTest extends AbstractGitHubWireMockTest {
GHWorkflow workflow = repo.getWorkflow("test-workflow.yml");
assertEquals("test-workflow", workflow.getName());
assertEquals(REPO_NAME, workflow.getRepository().getFullName());
assertEquals(".github/workflows/test-workflow.yml", workflow.getPath());
assertEquals("active", workflow.getState());
assertEquals("/repos/hub4j-test-org/GHWorkflowTest/actions/workflows/6817859", workflow.getUrl().getPath());