Skip to content

Commit a5f59c2

Browse files
Merge branch 'main' into chore/update-plugin-categories
2 parents d3b6a5a + 7ae7e28 commit a5f59c2

28 files changed

+1454
-221
lines changed

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
plugins {
2-
id "com.vanniktech.maven.publish" version "0.34.0"
2+
id "com.vanniktech.maven.publish" version "0.36.0"
33
id "io.kestra.gradle.inject-bom-versions" version "1.0.0"
44
id 'java-library'
55
id "idea"
@@ -114,7 +114,7 @@ configurations {
114114
}
115115

116116
dependencies {
117-
agent "org.aspectj:aspectjweaver:1.9.24"
117+
agent "org.aspectj:aspectjweaver:1.9.25.1"
118118
}
119119

120120
test {

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
version=1.1.0-SNAPSHOT
1+
version=1.0.1-SNAPSHOT
22
kestraVersion=1.2.3

src/main/java/io/kestra/plugin/templates/Example.java

Lines changed: 0 additions & 72 deletions
This file was deleted.

src/main/java/io/kestra/plugin/templates/Trigger.java

Lines changed: 0 additions & 59 deletions
This file was deleted.

src/main/java/io/kestra/plugin/templates/package-info.java

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package io.kestra.plugin.trello;
2+
import io.kestra.core.http.HttpRequest;
3+
import io.kestra.core.models.property.Property;
4+
import io.kestra.core.models.tasks.RunnableTask;
5+
import io.kestra.core.models.tasks.Task;
6+
import io.kestra.core.runners.RunContext;
7+
import io.swagger.v3.oas.annotations.media.Schema;
8+
import jakarta.validation.constraints.NotNull;
9+
import lombok.Builder;
10+
import lombok.EqualsAndHashCode;
11+
import lombok.Getter;
12+
import lombok.NoArgsConstructor;
13+
import lombok.experimental.SuperBuilder;
14+
15+
@SuperBuilder
16+
@EqualsAndHashCode
17+
@Getter
18+
@NoArgsConstructor
19+
public abstract class AbstractTrelloTask extends Task implements RunnableTask<io.kestra.core.models.tasks.Output> {
20+
21+
@Schema(title = "Trello API Key", description = "Your Trello API key")
22+
@NotNull
23+
protected Property<String> apiKey;
24+
25+
@Schema(title = "Trello API Token", description = "Your Trello API token")
26+
@NotNull
27+
protected Property<String> apiToken;
28+
29+
@Schema(title = "API Version", description = "Trello API version to use", defaultValue = "1")
30+
@Builder.Default
31+
protected Property<String> apiVersion = Property.ofValue("1");
32+
33+
@Schema(title = "Base API URL", description = "The base URL for the Trello API")
34+
@Builder.Default
35+
protected Property<String> apiBaseUrl = Property.ofValue("https://api.trello.com");
36+
37+
protected String buildApiUrl(RunContext runContext, String endpoint) throws Exception {
38+
String rVersion = runContext.render(this.apiVersion).as(String.class).orElse("1");
39+
String rBaseUrl = runContext.render(this.apiBaseUrl).as(String.class).orElse("https://api.trello.com");
40+
return String.format("%s/%s/%s", rBaseUrl, rVersion, endpoint);
41+
}
42+
43+
protected HttpRequest.HttpRequestBuilder addAuthHeaders(RunContext runContext, HttpRequest.HttpRequestBuilder builder) throws Exception {
44+
String rApiKey = runContext.render(this.apiKey).as(String.class).orElseThrow();
45+
String rApiToken = runContext.render(this.apiToken).as(String.class).orElseThrow();
46+
String authHeader = String.format("OAuth oauth_consumer_key=\"%s\", oauth_token=\"%s\"", rApiKey, rApiToken);
47+
return builder.addHeader("Authorization", authHeader);
48+
}
49+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
package io.kestra.plugin.trello.cards;
2+
3+
import com.fasterxml.jackson.databind.JsonNode;
4+
import io.kestra.core.http.HttpRequest;
5+
import io.kestra.core.http.HttpResponse;
6+
import io.kestra.core.http.client.HttpClient;
7+
import io.kestra.core.models.annotations.Example;
8+
import io.kestra.core.models.annotations.Plugin;
9+
import io.kestra.core.models.property.Property;
10+
import io.kestra.core.runners.RunContext;
11+
import io.kestra.core.serializers.JacksonMapper;
12+
import io.kestra.plugin.trello.AbstractTrelloTask;
13+
import io.swagger.v3.oas.annotations.media.Schema;
14+
import jakarta.validation.constraints.NotNull;
15+
import lombok.*;
16+
import lombok.experimental.SuperBuilder;
17+
18+
import java.net.URI;
19+
import java.net.URLEncoder;
20+
import java.nio.charset.StandardCharsets;
21+
22+
@SuperBuilder
23+
@NoArgsConstructor
24+
@Getter
25+
@ToString
26+
@EqualsAndHashCode
27+
28+
@Schema(
29+
title = "Add a comment to a Trello card",
30+
description = "Add a comment/action to an existing Trello card"
31+
)
32+
@Plugin(
33+
examples = {
34+
@Example(
35+
title = "Add a comment to a Trello card",
36+
full = true,
37+
code = """
38+
id: trello_add_comment
39+
namespace: company.team
40+
41+
tasks:
42+
- id: add_comment
43+
type: io.kestra.plugin.trello.cards.Comment
44+
apiKey: "{{ secret('TRELLO_API_KEY') }}"
45+
apiToken: "{{ secret('TRELLO_API_TOKEN') }}"
46+
cardId: "5abbe4b7ddc1b351ef961414"
47+
text: "This is my comment on the card"
48+
"""
49+
)
50+
}
51+
)
52+
public class Comment extends AbstractTrelloTask {
53+
54+
@Schema(title = "Card ID", description = "The ID of the card to add a comment to")
55+
@NotNull
56+
protected Property<String> cardId;
57+
58+
@Schema(title = "Comment Text", description = "The text of the comment")
59+
@NotNull
60+
protected Property<String> text;
61+
62+
@Override
63+
public io.kestra.core.models.tasks.Output run(RunContext runContext) throws Exception {
64+
String rId = runContext.render(this.cardId).as(String.class).orElseThrow();
65+
String rText = runContext.render(this.text).as(String.class).orElseThrow();
66+
67+
String url = buildApiUrl(runContext, "cards/" + rId + "/actions/comments") + "?text="
68+
+ URLEncoder.encode(rText, StandardCharsets.UTF_8);
69+
70+
HttpRequest.HttpRequestBuilder requestBuilder = HttpRequest.builder()
71+
.method("POST")
72+
.uri(URI.create(url))
73+
.addHeader("Accept", "application/json");
74+
75+
HttpRequest request = addAuthHeaders(runContext, requestBuilder).build();
76+
77+
try (HttpClient httpClient = HttpClient.builder()
78+
.runContext(runContext)
79+
.build()) {
80+
HttpResponse<String> response = httpClient.request(request, String.class);
81+
82+
if (response.getStatus().getCode() != 200) {
83+
throw new RuntimeException(
84+
"Failed to add comment: " + response.getStatus().getCode() + " - "
85+
+ response.getBody());
86+
}
87+
88+
JsonNode jsonNode = JacksonMapper.ofJson().readTree(response.getBody());
89+
90+
return Output.builder()
91+
.commentId(jsonNode.has("id")?jsonNode.get("id").asText():null)
92+
.build();
93+
}
94+
}
95+
96+
@Builder
97+
@Getter
98+
public static class Output implements io.kestra.core.models.tasks.Output {
99+
@Schema(title = "Comment ID")
100+
private final String commentId;
101+
}
102+
}

0 commit comments

Comments
 (0)