Skip to content

Commit d6edb6e

Browse files
authored
Azure DevOps (Microsoft Entra ID OAuth) migrate components (#19483)
* migrate azure_devops source * pnpm-lock.yaml * updates
1 parent e211496 commit d6edb6e

File tree

4 files changed

+162
-18
lines changed

4 files changed

+162
-18
lines changed
Lines changed: 74 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,80 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "azure_devops_microsoft_entra_id_oauth",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
eventType: {
8+
type: "string",
9+
label: "Event Type",
10+
description: "Event type to receive events for",
11+
async options() {
12+
const types = await this.listEventTypes();
13+
return types.filter(({ id }) => id !== "tfvc.checkin" && id !== "build.complete").map(({ id }) => id);
14+
},
15+
},
16+
projectId: {
17+
type: "string",
18+
label: "Project ID",
19+
description: "Project ID to receive events for",
20+
async options() {
21+
const projects = await this.listProjects();
22+
return projects?.map(({
23+
id: value, name: label,
24+
}) => ({
25+
value,
26+
label,
27+
})) || [];
28+
},
29+
},
30+
},
531
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
32+
_baseUrl() {
33+
return `https://dev.azure.com/${this.$auth.organization}/_apis`;
34+
},
35+
_makeRequest({
36+
$ = this, path, params, ...opts
37+
}) {
38+
return axios($, {
39+
url: `${this._baseUrl()}${path}`,
40+
headers: {
41+
"Authorization": `Bearer ${this.$auth.oauth_access_token}`,
42+
"content-type": "application/json",
43+
},
44+
params: {
45+
...params,
46+
"api-version": "7.1",
47+
},
48+
...opts,
49+
});
50+
},
51+
async listEventTypes(opts = {}) {
52+
const { value } = await this._makeRequest({
53+
path: "/hooks/publishers/tfs/eventtypes",
54+
...opts,
55+
});
56+
return value;
57+
},
58+
async listProjects(opts = {}) {
59+
const { value } = await this._makeRequest({
60+
path: "/projects",
61+
...opts,
62+
});
63+
return value;
64+
},
65+
createSubscription(opts = {}) {
66+
return this._makeRequest({
67+
method: "POST",
68+
path: "/hooks/subscriptions",
69+
...opts,
70+
});
71+
},
72+
deleteSubscription(subscriptionId, opts = {}) {
73+
return this._makeRequest({
74+
method: "DELETE",
75+
path: `/hooks/subscriptions/${subscriptionId}`,
76+
...opts,
77+
});
978
},
1079
},
11-
};
80+
};

components/azure_devops_microsoft_entra_id_oauth/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/azure_devops_microsoft_entra_id_oauth",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream Azure DevOps (Microsoft Entra ID OAuth) Components",
55
"main": "azure_devops_microsoft_entra_id_oauth.app.mjs",
66
"keywords": [
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.1.1"
1417
}
15-
}
18+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import azureDevops from "../../azure_devops_microsoft_entra_id_oauth.app.mjs";
2+
3+
export default {
4+
key: "azure_devops_microsoft_entra_id_oauth-new-event",
5+
name: "New Event (Instant)",
6+
description: "Emit new event for the specified event type.",
7+
version: "0.0.1",
8+
type: "source",
9+
dedupe: "unique",
10+
props: {
11+
azureDevops,
12+
db: "$.service.db",
13+
http: "$.interface.http",
14+
eventType: {
15+
propDefinition: [
16+
azureDevops,
17+
"eventType",
18+
],
19+
},
20+
projectId: {
21+
propDefinition: [
22+
azureDevops,
23+
"projectId",
24+
],
25+
},
26+
},
27+
hooks: {
28+
async activate() {
29+
const data = {
30+
url: this.http.endpoint,
31+
publisherId: "tfs",
32+
resourceVersion: "1.0",
33+
consumerId: "webHooks",
34+
consumerActionId: "httpRequest",
35+
consumerInputs: {
36+
url: this.http.endpoint,
37+
},
38+
publisherInputs: {
39+
projectId: this.projectId,
40+
},
41+
eventType: this.eventType,
42+
};
43+
const { id } = await this.azureDevops.createSubscription({
44+
data,
45+
});
46+
this._setHookId(id);
47+
},
48+
async deactivate() {
49+
const id = this._getHookId();
50+
await this.azureDevops.deleteSubscription(id);
51+
},
52+
},
53+
methods: {
54+
_getHookId() {
55+
return this.db.get("hookId");
56+
},
57+
_setHookId(hookId) {
58+
this.db.set("hookId", hookId);
59+
},
60+
generateMeta(body) {
61+
return {
62+
id: body.id,
63+
summary: `New ${this.eventType} event with ID ${body.id}`,
64+
ts: Date.parse(body.createdDate),
65+
};
66+
},
67+
},
68+
async run(event) {
69+
const { body } = event;
70+
const meta = this.generateMeta(body);
71+
this.$emit(body, meta);
72+
},
73+
};

pnpm-lock.yaml

Lines changed: 10 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)