Skip to content

Commit 5caa345

Browse files
committed
add HTML text support; update pixel category
1 parent b2bb166 commit 5caa345

File tree

5 files changed

+63
-8
lines changed

5 files changed

+63
-8
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,10 @@ Posts a comment in a given Asana Task
465465

466466
**Required** Is the comment pinned or not.
467467

468+
### `asana-task-comment-is-html`
469+
470+
**Optional** Set to `true` if the comment is in HTML format, `false` for plain text. Defaults to `false` if not provided. When set to `true`, the comment will be posted as HTML, allowing for rich formatting including links, mentions, and other HTML elements supported by Asana.
471+
468472
#### Example Usage
469473

470474
```yaml
@@ -486,6 +490,18 @@ jobs:
486490
asana-task-id: ${{ steps.find-asana-task-id.outputs.asanaTaskId }}
487491
asana-task-comment: 'PR: ${{ github.event.pull_request.html_url }} has been approved.'
488492
asana-task-comment-pinned: true
493+
asana-task-comment-is-html: false
494+
495+
- name: Add HTML Comment with Mention to Asana Task
496+
uses: ./actions
497+
id: post-html-comment
498+
with:
499+
action: 'post-comment-asana-task'
500+
asana-pat: ${{ secrets.asana_pat }}
501+
asana-task-id: ${{ steps.find-asana-task-id.outputs.asanaTaskId }}
502+
asana-task-comment: '<body><a data-asana-gid="USER_GID_HERE"/>@username</a>, please review this <a href="${{ github.event.pull_request.html_url }}">PR</a>.</body>'
503+
asana-task-comment-pinned: false
504+
asana-task-comment-is-html: true
489505
```
490506

491507
### Send a message in Mattermost

action.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,21 @@ function findAsanaTasks() {
8181
return foundTasks;
8282
}
8383

84-
async function createStory(client, taskId, text, isPinned) {
84+
async function createStory(client, taskId, text, isPinned, isHtml = false) {
8585
try {
86+
const opts = {};
8687
const body = {
8788
data: {
88-
text,
8989
is_pinned: isPinned,
9090
},
9191
};
92-
const opts = {};
92+
93+
if (isHtml) {
94+
body.data.html_text = text;
95+
} else {
96+
body.data.text = text;
97+
}
98+
9399
return await client.stories.createStoryForTask(body, taskId, opts);
94100
} catch (error) {
95101
console.error('rejecting promise', error);
@@ -491,6 +497,7 @@ async function postCommentAsanaTask() {
491497
const taskIds = getArrayFromInput(core.getInput('asana-task-id'));
492498
const taskComment = core.getInput('asana-task-comment');
493499
const isPinned = core.getInput('asana-task-comment-pinned') === 'true';
500+
const isHtml = core.getInput('asana-task-comment-is-html') === 'true';
494501

495502
if (taskIds.length === 0) {
496503
core.setFailed(`No valid task IDs provided`);
@@ -500,7 +507,7 @@ async function postCommentAsanaTask() {
500507
let success = true;
501508
for (const taskId of taskIds) {
502509
console.info(`Adding comment to Asana task ${taskId}`);
503-
const comment = await createStory(client, taskId, taskComment, isPinned);
510+
const comment = await createStory(client, taskId, taskComment, isPinned, isHtml);
504511
if (comment == null) {
505512
console.error(`Failed to add comment to task ${taskId}`);
506513
success = false;

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ inputs:
2727
asana-task-comment-pinned:
2828
description: 'Identifies if a comment in an Asana task needs to be pinned or not.'
2929
required: false
30+
asana-task-comment-is-html:
31+
description: 'Is the comment in HTML format. [true | false].'
32+
required: false
3033
asana-task-description:
3134
description: 'Description of the Asana task you want to create.'
3235
required: false

dist/index.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,21 @@ function findAsanaTasks() {
8787
return foundTasks;
8888
}
8989

90-
async function createStory(client, taskId, text, isPinned) {
90+
async function createStory(client, taskId, text, isPinned, isHtml = false) {
9191
try {
92+
const opts = {};
9293
const body = {
9394
data: {
94-
text,
9595
is_pinned: isPinned,
9696
},
9797
};
98-
const opts = {};
98+
99+
if (isHtml) {
100+
body.data.html_text = text;
101+
} else {
102+
body.data.text = text;
103+
}
104+
99105
return await client.stories.createStoryForTask(body, taskId, opts);
100106
} catch (error) {
101107
console.error('rejecting promise', error);
@@ -497,6 +503,7 @@ async function postCommentAsanaTask() {
497503
const taskIds = getArrayFromInput(core.getInput('asana-task-id'));
498504
const taskComment = core.getInput('asana-task-comment');
499505
const isPinned = core.getInput('asana-task-comment-pinned') === 'true';
506+
const isHtml = core.getInput('asana-task-comment-is-html') === 'true';
500507

501508
if (taskIds.length === 0) {
502509
core.setFailed(`No valid task IDs provided`);
@@ -506,7 +513,7 @@ async function postCommentAsanaTask() {
506513
let success = true;
507514
for (const taskId of taskIds) {
508515
console.info(`Adding comment to Asana task ${taskId}`);
509-
const comment = await createStory(client, taskId, taskComment, isPinned);
516+
const comment = await createStory(client, taskId, taskComment, isPinned, isHtml);
510517
if (comment == null) {
511518
console.error(`Failed to add comment to task ${taskId}`);
512519
success = false;

tests/action.test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,28 @@ describe('GitHub Asana Sync Action', () => {
10021002
expect(core.setFailed).not.toHaveBeenCalled();
10031003
});
10041004

1005+
it('should post a pinned HTML comment with user mention', async () => {
1006+
const htmlCommentWithMention = '<body><a data-asana-gid="123456789"/>@testuser</a>, please review this task.</body>';
1007+
mockGetInput({
1008+
action: 'post-comment-asana-task',
1009+
'asana-pat': 'mock-asana-pat',
1010+
'asana-task-id': 'single-task-id',
1011+
'asana-task-comment': htmlCommentWithMention,
1012+
'asana-task-comment-pinned': 'true',
1013+
'asana-task-comment-is-html': 'true',
1014+
});
1015+
1016+
await action();
1017+
1018+
expect(mockAsanaClient.stories.createStoryForTask).toHaveBeenCalledTimes(1);
1019+
expect(mockAsanaClient.stories.createStoryForTask).toHaveBeenCalledWith(
1020+
{ data: { html_text: htmlCommentWithMention, is_pinned: true } },
1021+
'single-task-id',
1022+
{},
1023+
);
1024+
expect(core.setFailed).not.toHaveBeenCalled();
1025+
});
1026+
10051027
it('should fail if no task IDs are provided', async () => {
10061028
mockGetInput({
10071029
action: 'post-comment-asana-task',

0 commit comments

Comments
 (0)