Skip to content

Commit 74f7853

Browse files
committed
circleci init
1 parent 101db92 commit 74f7853

File tree

7 files changed

+785
-2
lines changed

7 files changed

+785
-2
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import circleci from "../../circleci.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "circleci-add-comment",
6+
name: "Add Comment",
7+
description: "Adds a comment to an existing item. [See the documentation]().",
8+
version: "0.0.{{ts}}",
9+
type: "action",
10+
props: {
11+
circleci,
12+
itemId: {
13+
propDefinition: [
14+
circleci,
15+
"itemId",
16+
],
17+
},
18+
commentContent: {
19+
propDefinition: [
20+
circleci,
21+
"commentContent",
22+
],
23+
},
24+
userDetails: {
25+
propDefinition: [
26+
circleci,
27+
"userDetails",
28+
],
29+
optional: true,
30+
},
31+
},
32+
async run({ $ }) {
33+
const response = await this.circleci.addComment({
34+
itemId: this.itemId,
35+
commentContent: this.commentContent,
36+
userDetails: this.userDetails,
37+
});
38+
$.export("$summary", `Added comment to item ${this.itemId}`);
39+
return response;
40+
},
41+
};
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import circleci from "../../circleci.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "circleci-create-item",
6+
name: "Create Item",
7+
description: "Creates a new item in the CircleCI app. [See the documentation]()",
8+
version: "0.0.{{ts}}",
9+
type: "action",
10+
props: {
11+
circleci,
12+
title: {
13+
propDefinition: [
14+
circleci,
15+
"title",
16+
],
17+
},
18+
content: {
19+
propDefinition: [
20+
circleci,
21+
"content",
22+
],
23+
},
24+
metadata: {
25+
propDefinition: [
26+
circleci,
27+
"metadata",
28+
],
29+
optional: true,
30+
},
31+
},
32+
async run({ $ }) {
33+
const response = await this.circleci.createItem({
34+
title: this.title,
35+
content: this.content,
36+
metadata: this.metadata,
37+
});
38+
$.export("$summary", `Created item "${this.title}"`);
39+
return response;
40+
},
41+
};
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import circleci from "../../circleci.app.mjs";
2+
3+
export default {
4+
key: "circleci-update-item",
5+
name: "Update Item",
6+
description: "Updates an existing item in CircleCI. [See the documentation]()",
7+
version: "0.0.{{ts}}",
8+
type: "action",
9+
props: {
10+
circleci,
11+
itemId: {
12+
propDefinition: [
13+
circleci,
14+
"itemId",
15+
],
16+
},
17+
updateFields: {
18+
propDefinition: [
19+
circleci,
20+
"updateFields",
21+
],
22+
optional: false,
23+
},
24+
},
25+
async run({ $ }) {
26+
const response = await this.circleci.updateItem({
27+
itemId: this.itemId,
28+
updateFields: this.updateFields,
29+
});
30+
$.export("$summary", `Updated item with ID ${this.itemId}`);
31+
return response;
32+
},
33+
};
Lines changed: 173 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,182 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "circleci",
4-
propDefinitions: {},
6+
version: "0.0.{{ts}}",
7+
propDefinitions: {
8+
// Required for creating a new item
9+
title: {
10+
type: "string",
11+
label: "Title",
12+
description: "The title of the item",
13+
},
14+
content: {
15+
type: "string",
16+
label: "Content",
17+
description: "The content of the item",
18+
},
19+
// Required for updating an existing item
20+
itemId: {
21+
type: "string",
22+
label: "Item ID",
23+
description: "The unique identifier of the item",
24+
},
25+
// Required for adding a comment
26+
commentContent: {
27+
type: "string",
28+
label: "Comment Content",
29+
description: "The content of the comment",
30+
},
31+
// Optional for creating a new item
32+
metadata: {
33+
type: "string",
34+
label: "Metadata",
35+
description: "Optional metadata as JSON string",
36+
optional: true,
37+
},
38+
// Optional for updating an existing item
39+
updateFields: {
40+
type: "string",
41+
label: "Fields to Update",
42+
description: "Fields to update in the item as JSON string",
43+
optional: true,
44+
},
45+
// Optional for adding a comment to an existing item
46+
userDetails: {
47+
type: "string",
48+
label: "User Details",
49+
description: "Optional user details as JSON string",
50+
optional: true,
51+
},
52+
// Optional filters for new item creation events
53+
newItemType: {
54+
type: "string",
55+
label: "Item Type",
56+
description: "Filter by item type",
57+
optional: true,
58+
},
59+
newItemStatus: {
60+
type: "string",
61+
label: "Status",
62+
description: "Filter by status",
63+
optional: true,
64+
},
65+
// Optional filters for item update events
66+
updatedItemFields: {
67+
type: "string",
68+
label: "Updated Fields",
69+
description: "Filter by updated fields",
70+
optional: true,
71+
},
72+
updatedItemType: {
73+
type: "string",
74+
label: "Item Type",
75+
description: "Filter by item type",
76+
optional: true,
77+
},
78+
// Optional filters for comment addition events
79+
commentItemType: {
80+
type: "string",
81+
label: "Item Type",
82+
description: "Filter by item type",
83+
optional: true,
84+
},
85+
commentUser: {
86+
type: "string",
87+
label: "User",
88+
description: "Filter by user",
89+
optional: true,
90+
},
91+
},
592
methods: {
6-
// this.$auth contains connected account data
93+
// This method logs the authentication keys
794
authKeys() {
895
console.log(Object.keys(this.$auth));
996
},
97+
// Base URL for CircleCI API
98+
_baseUrl() {
99+
return "https://circleci.com/api/v2";
100+
},
101+
// Common method to make API requests
102+
async _makeRequest(opts = {}) {
103+
const {
104+
$ = this, method = "GET", path = "/", headers, ...otherOpts
105+
} = opts;
106+
return axios($, {
107+
method,
108+
url: this._baseUrl() + path,
109+
headers: {
110+
...headers,
111+
Authorization: `Bearer ${this.$auth.api_key}`,
112+
},
113+
...otherOpts,
114+
});
115+
},
116+
// Create a new item
117+
async createItem(opts = {}) {
118+
const {
119+
title, content, metadata, ...otherOpts
120+
} = opts;
121+
const data = {
122+
title,
123+
content,
124+
};
125+
if (metadata) {
126+
try {
127+
data.metadata = JSON.parse(metadata);
128+
} catch (error) {
129+
throw new Error("Invalid JSON for metadata");
130+
}
131+
}
132+
return this._makeRequest({
133+
method: "POST",
134+
path: "/items",
135+
data,
136+
...otherOpts,
137+
});
138+
},
139+
// Update an existing item
140+
async updateItem(opts = {}) {
141+
const {
142+
itemId, updateFields, ...otherOpts
143+
} = opts;
144+
const data = {};
145+
if (updateFields) {
146+
try {
147+
Object.assign(data, JSON.parse(updateFields));
148+
} catch (error) {
149+
throw new Error("Invalid JSON for updateFields");
150+
}
151+
}
152+
return this._makeRequest({
153+
method: "PUT",
154+
path: `/items/${itemId}`,
155+
data,
156+
...otherOpts,
157+
});
158+
},
159+
// Add a comment to an existing item
160+
async addComment(opts = {}) {
161+
const {
162+
itemId, commentContent, userDetails, ...otherOpts
163+
} = opts;
164+
const data = {
165+
content: commentContent,
166+
};
167+
if (userDetails) {
168+
try {
169+
data.user = JSON.parse(userDetails);
170+
} catch (error) {
171+
throw new Error("Invalid JSON for userDetails");
172+
}
173+
}
174+
return this._makeRequest({
175+
method: "POST",
176+
path: `/items/${itemId}/comments`,
177+
data,
178+
...otherOpts,
179+
});
180+
},
10181
},
11182
};

0 commit comments

Comments
 (0)