|
| 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 | +} |
0 commit comments