-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add get and list workflows from github actions API (#197)
* Add get and list workflows from github actions API * Update workflows client hierarchy according to github API * Fix import
- Loading branch information
Showing
10 changed files
with
474 additions
and
0 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
src/main/java/com/spotify/github/v3/clients/ActionsClient.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,46 @@ | ||
/*- | ||
* -\-\- | ||
* github-api | ||
* -- | ||
* Copyright (C) 2016 - 2020 Spotify AB | ||
* -- | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* -/-/- | ||
*/ | ||
|
||
package com.spotify.github.v3.clients; | ||
|
||
public class ActionsClient { | ||
private final String owner; | ||
private final String repo; | ||
private final GitHubClient github; | ||
|
||
ActionsClient(final GitHubClient github, final String owner, final String repo) { | ||
this.github = github; | ||
this.owner = owner; | ||
this.repo = repo; | ||
} | ||
|
||
static ActionsClient create(final GitHubClient github, final String owner, final String repo) { | ||
return new ActionsClient(github, owner, repo); | ||
} | ||
|
||
/** | ||
* Workflows API client | ||
* | ||
* @return Workflows API client | ||
*/ | ||
public WorkflowsClient createWorkflowsClient() { | ||
return WorkflowsClient.create(github, owner, repo); | ||
} | ||
} |
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
73 changes: 73 additions & 0 deletions
73
src/main/java/com/spotify/github/v3/clients/WorkflowsClient.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,73 @@ | ||
/*- | ||
* -\-\- | ||
* github-api | ||
* -- | ||
* Copyright (C) 2016 - 2020 Spotify AB | ||
* -- | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* -/-/- | ||
*/ | ||
|
||
package com.spotify.github.v3.clients; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import com.spotify.github.v3.workflows.WorkflowsRepositoryResponseList; | ||
import com.spotify.github.v3.workflows.WorkflowsResponse; | ||
|
||
import javax.ws.rs.core.HttpHeaders; | ||
import java.util.Map; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
/** Workflows API client */ | ||
public class WorkflowsClient { | ||
private static final String LIST_REPOSITORY_WORKFLOWS_URI = "/repos/%s/%s/actions/workflows"; | ||
private static final String GET_WORKFLOW_URI = "/repos/%s/%s/actions/workflows/%s"; | ||
|
||
private final GitHubClient github; | ||
private final String owner; | ||
private final String repo; | ||
|
||
private final Map<String, String> extraHeaders = | ||
ImmutableMap.of(HttpHeaders.ACCEPT, "application/vnd.github+json"); | ||
|
||
public WorkflowsClient(final GitHubClient github, final String owner, final String repo) { | ||
this.github = github; | ||
this.owner = owner; | ||
this.repo = repo; | ||
} | ||
|
||
static WorkflowsClient create(final GitHubClient github, final String owner, final String repo) { | ||
return new WorkflowsClient(github, owner, repo); | ||
} | ||
|
||
/** | ||
* List workflows for a repository. | ||
* | ||
* @return a list of workflows for the repository | ||
*/ | ||
public CompletableFuture<WorkflowsRepositoryResponseList> listWorkflows() { | ||
final String path = String.format(LIST_REPOSITORY_WORKFLOWS_URI, owner, repo); | ||
return github.request(path, WorkflowsRepositoryResponseList.class, extraHeaders); | ||
} | ||
|
||
/** | ||
* Gets a workflow by id. | ||
* | ||
* @param id the workflow id | ||
* @return a WorkflowsResponse | ||
*/ | ||
public CompletableFuture<WorkflowsResponse> getWorkflow(final int id) { | ||
final String path = String.format(GET_WORKFLOW_URI, owner, repo, id); | ||
return github.request(path, WorkflowsResponse.class, extraHeaders); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
src/main/java/com/spotify/github/v3/workflows/WorkflowsRepositoryResponseList.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,51 @@ | ||
/*- | ||
* -\-\- | ||
* github-api | ||
* -- | ||
* Copyright (C) 2016 - 2020 Spotify AB | ||
* -- | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* -/-/- | ||
*/ | ||
|
||
package com.spotify.github.v3.workflows; | ||
|
||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
import com.spotify.github.GithubStyle; | ||
import org.immutables.value.Value; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* The WorkflowsResponse list resource | ||
* | ||
* @see "https://docs.github.com/en/rest/actions/workflows#list-repository-workflows" | ||
*/ | ||
@Value.Immutable | ||
@GithubStyle | ||
@JsonDeserialize(as = ImmutableWorkflowsRepositoryResponseList.class) | ||
public interface WorkflowsRepositoryResponseList { | ||
/** | ||
* The count of workflows in the response | ||
* | ||
* @return the int | ||
*/ | ||
int totalCount(); | ||
|
||
/** | ||
* Workflows list. | ||
* | ||
* @return the list of workflows | ||
*/ | ||
List<WorkflowsResponse> workflows(); | ||
} |
93 changes: 93 additions & 0 deletions
93
src/main/java/com/spotify/github/v3/workflows/WorkflowsResponse.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,93 @@ | ||
/*- | ||
* -\-\- | ||
* github-api | ||
* -- | ||
* Copyright (C) 2016 - 2020 Spotify AB | ||
* -- | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* -/-/- | ||
*/ | ||
|
||
package com.spotify.github.v3.workflows; | ||
|
||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
import com.spotify.github.GithubStyle; | ||
import org.immutables.value.Value; | ||
|
||
import java.time.ZonedDateTime; | ||
|
||
@Value.Immutable | ||
@GithubStyle | ||
@JsonDeserialize(as = ImmutableWorkflowsResponse.class) | ||
public interface WorkflowsResponse { | ||
/** | ||
* The Workflow ID. | ||
* | ||
* @return the int | ||
*/ | ||
int id(); | ||
|
||
/** Node ID */ | ||
String nodeId(); | ||
|
||
/** Name. */ | ||
String name(); | ||
|
||
/** The workflow path. */ | ||
String path(); | ||
|
||
/** Indicates the state of the workflow. */ | ||
WorkflowsState state(); | ||
|
||
/** | ||
* Created At | ||
* | ||
* @return The time when the workflow was created | ||
*/ | ||
ZonedDateTime createdAt(); | ||
|
||
/** | ||
* Updated At | ||
* | ||
* @return The time when the workflow was updated | ||
*/ | ||
ZonedDateTime updatedAt(); | ||
|
||
/** | ||
* Deleted At | ||
* | ||
* @return The time when the workflow was deleted | ||
*/ | ||
ZonedDateTime deletedAt(); | ||
|
||
/** | ||
* Url string. | ||
* | ||
* @return the string | ||
*/ | ||
String url(); | ||
|
||
/** | ||
* Html url string. | ||
* | ||
* @return the string | ||
*/ | ||
String htmlUrl(); | ||
|
||
/** | ||
* Badge Url string. | ||
* | ||
* @return the string | ||
*/ | ||
String badgeUrl(); | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/com/spotify/github/v3/workflows/WorkflowsState.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,30 @@ | ||
/*- | ||
* -\-\- | ||
* github-api | ||
* -- | ||
* Copyright (C) 2016 - 2020 Spotify AB | ||
* -- | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* -/-/- | ||
*/ | ||
|
||
package com.spotify.github.v3.workflows; | ||
|
||
/** The Workflow State. */ | ||
public enum WorkflowsState { | ||
active, | ||
deleted, | ||
disabled_fork, | ||
disabled_inactivity, | ||
disabled_manually | ||
} |
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
Oops, something went wrong.