Skip to content

Commit db2dd17

Browse files
committed
✨ added_github_asana_action
1 parent 61a153b commit db2dd17

File tree

2,239 files changed

+377198
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,239 files changed

+377198
-0
lines changed

.gitignore

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
8+
# Runtime data
9+
pids
10+
*.pid
11+
*.seed
12+
*.pid.lock
13+
14+
# Directory for instrumented libs generated by jscoverage/JSCover
15+
lib-cov
16+
17+
# Coverage directory used by tools like istanbul
18+
coverage
19+
20+
# nyc test coverage
21+
.nyc_output
22+
23+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
24+
.grunt
25+
26+
# Bower dependency directory (https://bower.io/)
27+
bower_components
28+
29+
# node-waf configuration
30+
.lock-wscript
31+
32+
# Compiled binary addons (https://nodejs.org/api/addons.html)
33+
build/Release
34+
35+
# Dependency directories
36+
jspm_packages/
37+
38+
# TypeScript v1 declaration files
39+
typings/
40+
41+
# Optional npm cache directory
42+
.npm
43+
44+
# Optional eslint cache
45+
.eslintcache
46+
47+
# Optional REPL history
48+
.node_repl_history
49+
50+
# Output of 'npm pack'
51+
*.tgz
52+
53+
# Yarn Integrity file
54+
.yarn-integrity
55+
56+
# dotenv environment variables file
57+
.env
58+
59+
# next.js build output
60+
.next
61+
.idea

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
# Github-Asana action
3+
4+
This action integrates asana with github.
5+
6+
### Prerequisites
7+
8+
- Asana account with the permission on the particular project you want to integrate with.
9+
- Must provide the task url in the PR description.
10+
11+
## Inputs
12+
13+
### `asana-pat`
14+
15+
**Required** Your public access token of asana, you can find it in [asana docs](https://developers.asana.com/docs/#authentication-basics).
16+
17+
### `trigger-phrase`
18+
19+
**Required** Prefix before the task i.e ASANA TASK: https://app.asana.com/1/2/3/.
20+
21+
### `task-comment`
22+
23+
**Optional** If any comment is provided, the action will add a comment to the specified asana task with the text & pull request link.
24+
25+
### `target-section`
26+
27+
**Optional** Add/Move the task to the provided section i.e `merged`, `review`.
28+
29+
30+
## Example usage
31+
32+
```yaml
33+
uses: https://github.com/insurify/github-actions@master
34+
with:
35+
asana-pat: 'Your PAT'
36+
target-section: 'In Review'
37+
task-comment: 'View Pull Request Here: '
38+
trigger-phrase: 'Asana Task:'
39+
```

action.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: 'Asana Git'
2+
description: 'Asana Github Actions'
3+
inputs:
4+
asana-pat:
5+
description: 'Asana Public Access Token.'
6+
required: true
7+
task-comment:
8+
description: 'Provide text, which will add a comment with the pull request link to the asana task.'
9+
required: false
10+
target-section:
11+
description: 'Provide the name of an Asana projects section or column where you want to move the task.'
12+
required: false
13+
trigger-phrase:
14+
description: 'Prefix before the task i.e ASANA TASK: https://app.asana.com/1/2/3'
15+
required: true
16+
runs:
17+
using: 'node12'
18+
main: 'index.js'

index.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
const core = require('@actions/core');
2+
const github = require('@actions/github');
3+
const asana = require('asana');
4+
5+
async function asanaOperations(
6+
asanaPAT,
7+
projectId,
8+
taskId,
9+
sectionName,
10+
taskComment
11+
) {
12+
const client = asana.Client.create({
13+
defaultHeaders: { 'asana-enable': 'new-sections,string_ids' },
14+
logAsanaChangeWarnings: false
15+
}).useAccessToken(asanaPAT);
16+
17+
try {
18+
if (sectionName) {
19+
let project = await client.sections.findByProject(projectId);
20+
if (project) {
21+
let requiredSection = project.find(data => data.name === sectionName);
22+
if (requiredSection) {
23+
await client.sections.addTask(requiredSection.gid, { task: taskId });
24+
core.info('Moved to: ' + requiredSection.name);
25+
} else {
26+
core.error('Asana section ' + sectionName + ' not found.');
27+
}
28+
} else {
29+
core.error('Asana project with id ' + projectId + ' not found.');
30+
}
31+
}
32+
if (taskComment) {
33+
await client.tasks.addComment(taskId, {
34+
text: taskComment
35+
});
36+
core.info('Added the pull request link to the Asana task.');
37+
}
38+
} catch (ex) {
39+
core.error(ex.value);
40+
}
41+
}
42+
43+
try {
44+
const ASANA_PAT = core.getInput('asana-pat'),
45+
SECTION_NAME = core.getInput('target-section'),
46+
TRIGGER_PHRASE = core.getInput('trigger-phrase'),
47+
TASK_COMMENT = core.getInput('task-comment'),
48+
PULL_REQUEST = github.context.payload.pull_request,
49+
REGEX = new RegExp(
50+
`\\*\\*${TRIGGER_PHRASE}\\*\\* \\[(.*?)\\]\\(https:\\/\\/app.asana.com\\/(\\d+)\\/(?<project>\\d+)\\/(?<task>\\d+).*?\\)`,
51+
'g'
52+
);
53+
let taskComment = null,
54+
parseAsanaURL = null;
55+
56+
if (TASK_COMMENT) {
57+
taskComment = `${TASK_COMMENT} ${PULL_REQUEST.html_url}`;
58+
}
59+
while ((parseAsanaURL = REGEX.exec(PULL_REQUEST.body)) !== null) {
60+
let projectId = parseAsanaURL.groups.project,
61+
taskId = parseAsanaURL.groups.task;
62+
if (projectId && taskId) {
63+
asanaOperations(ASANA_PAT, projectId, taskId, SECTION_NAME, taskComment);
64+
} else {
65+
core.info('Invalid Asana task URL after the trigger phrase' + TRIGGER_PHRASE);
66+
}
67+
}
68+
} catch (error) {
69+
core.error(error.message);
70+
}

node_modules/.bin/semver

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/sshpk-conv

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/sshpk-sign

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/sshpk-verify

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/uuid

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/which

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)