Skip to content

Commit 9fce3e9

Browse files
2034 - added List Repository Issues action
1 parent da7cfd4 commit 9fce3e9

File tree

3 files changed

+116
-0
lines changed

3 files changed

+116
-0
lines changed

server/libs/modules/components/github/src/main/java/com/bytechef/component/github/GithubComponentHandler.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.bytechef.component.github.action.GithubCreateCommentOnIssueAction;
2828
import com.bytechef.component.github.action.GithubCreateIssueAction;
2929
import com.bytechef.component.github.action.GithubGetIssueAction;
30+
import com.bytechef.component.github.action.GithubListRepositoryIssuesAction;
3031
import com.bytechef.component.github.action.GithubStarRepositoryAction;
3132
import com.bytechef.component.github.trigger.GithubNewIssueTrigger;
3233
import com.bytechef.component.github.trigger.GithubNewPullRequestTrigger;
@@ -50,6 +51,7 @@ public class GithubComponentHandler implements ComponentHandler {
5051
GithubCreateCommentOnIssueAction.ACTION_DEFINITION,
5152
GithubCreateIssueAction.ACTION_DEFINITION,
5253
GithubGetIssueAction.ACTION_DEFINITION,
54+
GithubListRepositoryIssuesAction.ACTION_DEFINITION,
5355
GithubStarRepositoryAction.ACTION_DEFINITION)
5456
.icon("path:assets/github.svg")
5557
.triggers(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Copyright 2023-present ByteChef Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.bytechef.component.github.action;
18+
19+
import static com.bytechef.component.definition.ComponentDsl.action;
20+
import static com.bytechef.component.definition.ComponentDsl.array;
21+
import static com.bytechef.component.definition.ComponentDsl.outputSchema;
22+
import static com.bytechef.component.definition.ComponentDsl.string;
23+
import static com.bytechef.component.definition.Context.Http.responseType;
24+
import static com.bytechef.component.github.constant.GithubConstants.REPOSITORY;
25+
import static com.bytechef.component.github.util.GithubUtils.getOwnerName;
26+
27+
import com.bytechef.component.definition.ActionContext;
28+
import com.bytechef.component.definition.ComponentDsl.ModifiableActionDefinition;
29+
import com.bytechef.component.definition.Context.Http.ResponseType;
30+
import com.bytechef.component.definition.OptionsDataSource.ActionOptionsFunction;
31+
import com.bytechef.component.definition.Parameters;
32+
import com.bytechef.component.definition.TypeReference;
33+
import com.bytechef.component.github.util.GithubUtils;
34+
import java.util.List;
35+
import java.util.Map;
36+
37+
/**
38+
* @author Nikolina Spehar
39+
*/
40+
public class GithubListRepositoryIssuesAction {
41+
42+
public static final ModifiableActionDefinition ACTION_DEFINITION = action("listRepositoryIssues")
43+
.title("List Issues")
44+
.description("Get list of issues from the repository")
45+
.properties(
46+
string(REPOSITORY)
47+
.label("Repository")
48+
.options((ActionOptionsFunction<String>) GithubUtils::getRepositoryOptions)
49+
.description("The name of the repository")
50+
.required(true))
51+
.output(
52+
outputSchema(
53+
array()))
54+
.perform(GithubListRepositoryIssuesAction::perform);
55+
56+
private GithubListRepositoryIssuesAction() {
57+
}
58+
59+
public static List<Map<String, Object>> perform(
60+
Parameters inputParameters, Parameters connectionParameters, ActionContext context) {
61+
62+
return context
63+
.http(http -> http.get(
64+
"/repos/" + getOwnerName(context) + "/" + inputParameters.getRequiredString(REPOSITORY) + "/issues"))
65+
.configuration(responseType(ResponseType.JSON))
66+
.execute()
67+
.getBody(new TypeReference<>() {});
68+
}
69+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright 2023-present ByteChef Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.bytechef.component.github.action;
18+
19+
import static org.junit.jupiter.api.Assertions.assertEquals;
20+
import static org.mockito.ArgumentMatchers.any;
21+
import static org.mockito.Mockito.when;
22+
23+
import com.bytechef.component.definition.Parameters;
24+
import com.bytechef.component.definition.TypeReference;
25+
import com.bytechef.component.test.definition.MockParametersFactory;
26+
import java.util.Map;
27+
import org.junit.jupiter.api.Test;
28+
29+
/**
30+
* @author Nikolina Spehar
31+
*/
32+
class GithubListRepositoryIssuesActionTest extends AbstractGithubActionTest {
33+
34+
private final Parameters mockedParameters = MockParametersFactory.create(Map.of());
35+
36+
@Test
37+
void testPerform() {
38+
when(mockedResponse.getBody(any(TypeReference.class)))
39+
.thenReturn(responseMap);
40+
41+
Object result = GithubGetIssueAction.perform(mockedParameters, mockedParameters, mockedContext);
42+
43+
assertEquals(responseMap, result);
44+
}
45+
}

0 commit comments

Comments
 (0)