Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ACTION] Microsoft Planner actions #11921

Merged
merged 1 commit into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
key: "microsoft_365_planner-create-bucket",
name: "Create Bucket",
description: "Create a new bucket in Microsoft 365 Planner. [See the documentation](https://learn.microsoft.com/en-us/graph/api/planner-post-buckets)",
version: "0.0.1",
version: "0.0.2",
type: "action",
props: {
microsoft365Planner,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
key: "microsoft_365_planner-create-plan",
name: "Create Plan",
description: "Create a new plan in Microsoft 365 Planner. [See the documentation](https://learn.microsoft.com/en-us/graph/api/planner-post-plans)",
version: "0.0.1",
version: "0.0.2",
type: "action",
props: {
microsoft365Planner,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
key: "microsoft_365_planner-create-task",
name: "Create Task",
description: "Create a new task in Microsoft 365 Planner. [See the documentation](https://learn.microsoft.com/en-us/graph/api/planner-post-tasks)",
version: "0.0.1",
version: "0.0.2",
type: "action",
props: {
microsoft365Planner,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import app from "../../microsoft_365_planner.app.mjs";

export default {
key: "microsoft_365_planner-list-user-tasks",
name: "List User Tasks",
description: "List all user tasks in Microsoft 365 Planner. [See the documentation](https://learn.microsoft.com/en-us/graph/api/planneruser-list-tasks?view=graph-rest-1.0&tabs=http)",
version: "0.0.1",
type: "action",
props: {
app,
},
async run({ $ }) {
const response = await this.app.listUserTasks({
$,
});

$.export("$summary", `Successfully retrieved \`${response?.value?.length}\` task(s).`);

return response;
},
};
192 changes: 192 additions & 0 deletions components/microsoft_365_planner/actions/update-task/update-task.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
import app from "../../microsoft_365_planner.app.mjs";
import utils from "../../common/utils.mjs";

export default {
key: "microsoft_365_planner-update-task",
name: "Update Task",
description: "Updates a task in Microsoft 365 Planner. [See the documentation](https://learn.microsoft.com/en-us/graph/api/plannertask-update?view=graph-rest-1.0&tabs=http)",
version: "0.0.1",
type: "action",
props: {
app,
taskId: {
propDefinition: [
app,
"userTaskId",
],
},
title: {
type: "string",
label: "Title",
description: "Title of the task",
optional: true,
},
priority: {
type: "integer",
label: "Priority",
description: "Priority of the task. The valid range of values is between `0` and `10`, with the increasing value being lower priority (`0` has the highest priority and `10` has the lowest priority)",
optional: true,
min: 0,
max: 10,
},
percentComplete: {
type: "integer",
label: "Percent Complete",
description: "Percentage of task completion. When set to `100`, the task is considered completed.",
optional: true,
},
dueDateTime: {
type: "string",
label: "Due Date Time",
description: "Date and time at which the task is due. The Timestamp type represents date and time information using ISO 8601 format and is always in UTC time. For example, midnight UTC on Jan 1, 2014 is `2014-01-01T00:00:00Z`.",
optional: true,
},
startDateTime: {
type: "string",
label: "Start Date Time",
description: "Date and time at which the task starts. The Timestamp type represents date and time information using ISO 8601 format and is always in UTC time. For example, midnight UTC on Jan 1, 2014 is `2014-01-01T00:00:00Z`.",
optional: true,
},
orderHint: {
type: "string",
label: "Order Hint",
description: "Hint used to order items of this type in a list view. The format is defined in [Using order hints in Planner](https://learn.microsoft.com/en-us/graph/api/resources/planner-order-hint-format?view=graph-rest-1.0).",
optional: true,
},
assigneePriority: {
type: "string",
label: "Assignee Priority",
description: "Hint used to order items of this type in a list view. The format is defined as outlined [here](https://learn.microsoft.com/en-us/graph/api/resources/planner-order-hint-format?view=graph-rest-1.0).",
optional: true,
},
groupId: {
optional: true,
propDefinition: [
app,
"groupId",
],
},
conversationThreadId: {
propDefinition: [
app,
"conversationThreadId",
({ groupId }) => ({
groupId,
}),
],
},
assignmentIds: {
propDefinition: [
app,
"assigneeIds",
({ groupId }) => ({
groupId,
}),
],
},
planId: {
optional: true,
propDefinition: [
app,
"planId",
({ groupId }) => ({
groupId,
}),
],
},
bucketId: {
propDefinition: [
app,
"bucketId",
({ planId }) => ({
planId,
}),
],
},
appliedCategories: {
type: "string[]",
label: "Applied Categories",
description: "The categories to which the task has been applied. See [applied Categories](https://learn.microsoft.com/en-us/graph/api/resources/plannerappliedcategories?view=graph-rest-1.0) for possible values.",
optional: true,
options: Array.from({
length: 6,
}, (_, idx) => `category${idx + 1}`),
},
},
methods: {
getAppliedCategories(appliedCategories = []) {
return utils.parseArray(appliedCategories)?.reduce((acc, category) => ({
...acc,
[category]: true,
}), {});
},
getAssignments(assignmentIds = []) {
return utils.parseArray(assignmentIds)?.reduce((acc, id) => ({
...acc,
[id]: {
"@odata.type": "microsoft.graph.plannerAssignment",
"orderHint": " !",
},
}), {});
},
updateTask({
taskId, ...args
} = {}) {
return this.app._makeRequest({
method: "PATCH",
path: `/planner/tasks/${taskId}`,
...args,
});
},
},
async run({ $ }) {
const {
app,
getAssignments,
getAppliedCategories,
updateTask,
taskId,
title,
priority,
percentComplete,
startDateTime,
dueDateTime,
assigneePriority,
conversationThreadId,
assignmentIds,
bucketId,
appliedCategories,
} = this;

const { ["@odata.etag"]: etag } = await app.getTask({
$,
taskId,
});

const response = await updateTask({
$,
taskId,
headers: {
"Content-Type": "application/json",
"If-Match": etag,
"Prefer": "return=representation",
},
data: {
title,
priority,
percentComplete,
startDateTime,
dueDateTime,
assigneePriority,
conversationThreadId,
bucketId,
assignments: getAssignments(assignmentIds),
appliedCategories: getAppliedCategories(appliedCategories),
},
});

$.export("$summary", `Successfully updated task with ID \`${response.id}\`.`);

return response;
},
};
28 changes: 28 additions & 0 deletions components/microsoft_365_planner/common/utils.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { ConfigurationError } from "@pipedream/platform";

function parseArray(value) {
try {
if (!value) {
return [];
}

if (Array.isArray(value)) {
return value;
}

const parsedValue = JSON.parse(value);

if (!Array.isArray(parsedValue)) {
throw new Error("Not an array");
}

return parsedValue;

} catch (e) {
throw new ConfigurationError("Make sure the custom expression contains a valid array object");
}
}

export default {
parseArray,
};
66 changes: 60 additions & 6 deletions components/microsoft_365_planner/microsoft_365_planner.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -156,25 +156,57 @@ export default {
};
},
},
userTaskId: {
type: "string",
label: "User Task ID",
description: "Identifier of a user task",
async options() {
const response = await this.listUserTasks();
return response.value?.map(({
id: value, title: label,
}) => ({
value,
label,
}));
},
},
conversationThreadId: {
type: "string",
label: "Conversation Thread ID",
description: "Identifier of the conversation thread associated with the task.",
optional: true,
async options({ groupId }) {
if (!groupId) {
return [];
}
const response = await this.listThreads({
groupId,
});
return response.value?.map(({
id: value, topic: label,
}) => ({
value,
label,
}));
},
},
},
methods: {
_baseUrl() {
return "https://graph.microsoft.com/v1.0";
},
_headers() {
_headers(headers) {
return {
...headers,
Authorization: `Bearer ${this.$auth.oauth_access_token}`,
};
},
_makeRequest({
$ = this,
path,
url,
...args
$ = this, path, url, headers, ...args
}) {
return axios($, {
url: url || `${this._baseUrl()}${path}`,
headers: this._headers(),
headers: this._headers(headers),
...args,
});
},
Expand Down Expand Up @@ -237,6 +269,28 @@ export default {
...args,
});
},
getTask({
taskId, ...args
}) {
return this._makeRequest({
path: `/planner/tasks/${taskId}`,
...args,
});
},
listUserTasks(args = {}) {
return this._makeRequest({
path: "/me/planner/tasks",
...args,
});
},
listThreads({
groupId, ...args
}) {
return this._makeRequest({
path: `/groups/${groupId}/threads`,
...args,
});
},
async *paginate({
fn, args,
}) {
Expand Down
4 changes: 2 additions & 2 deletions components/microsoft_365_planner/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/microsoft_365_planner",
"version": "0.1.0",
"version": "0.2.0",
"description": "Pipedream Microsoft 365 Planner Components",
"main": "microsoft_365_planner.app.mjs",
"keywords": [
Expand All @@ -13,6 +13,6 @@
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^1.5.1"
"@pipedream/platform": "^1.6.5"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default {
key: "microsoft_365_planner-new-plan-created",
name: "New Plan Created",
description: "Emit new event when a new Plan is created in Microsoft 365 Planner",
version: "0.0.1",
version: "0.0.2",
type: "source",
dedupe: "unique",
props: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default {
key: "microsoft_365_planner-new-task-created",
name: "New Task Created",
description: "Emit new event when a new Task is created in Microsoft 365 Planner",
version: "0.0.1",
version: "0.0.2",
type: "source",
dedupe: "unique",
props: {
Expand Down
Loading
Loading