Skip to content

Commit

Permalink
chore: added task creation functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
FabiLo22 committed Nov 25, 2024
1 parent 28ccd4c commit 6c09c2a
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 52 deletions.
48 changes: 35 additions & 13 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

20 changes: 2 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "typescript-action",
"description": "Givve Asana Management",
"version": "v0.0.5",
"version": "v0.0.6",
"author": "PL Gutscheinsysteme GmbH",
"private": true,
"homepage": "https://github.com/givve/github_asana_action",
Expand Down Expand Up @@ -78,7 +78,6 @@
},
"devDependencies": {
"@jest/globals": "^29.7.0",
"@types/asana": "^0.18.16",
"@types/jest": "^29.5.13",
"@types/node": "^22.5.5",
"@typescript-eslint/eslint-plugin": "^8.6.0",
Expand Down
22 changes: 19 additions & 3 deletions src/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ export class GitHub {
constructor() {}

async performAuth() {
console.log('GITHUB_TOKEN:', process.env.GITHUB_TOKEN)
const auth = octoAuth.createActionAuth()
const authentication = await auth()

this.requestWithAuth = Request.request.defaults({
request: {
hook: auth.hook
Expand All @@ -25,7 +23,7 @@ export class GitHub {
})
}

async getPR(): Promise<string[]> {
async getPR(): Promise<any> {
return new Promise(async (resolve, reject) => {
const { data: issue, error: error } = await this.requestWithAuth(
'GET /repos/{owner}/{repo}/issues/{pull_number}',
Expand All @@ -39,4 +37,22 @@ export class GitHub {
resolve(issue)
})
}

async updatePRDescription(pr: any, task: any) {
return new Promise(async (resolve, reject) => {
console.log(task)
// Beschreibung aktualisieren
await this.requestWithAuth(
'PATCH /repos/{owner}/{repo}/pulls/{pull_number}',
{
owner: 'givve',
repo: 'givve',
pull_number: pr.number,
body: pr.body + '<br \\>' + task.data.permalink_url
}
)

resolve(true)
})
}
}
42 changes: 27 additions & 15 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as core from '@actions/core'
import { GitHub } from './github.js'
import * as _ from 'lodash'
import * as asana from 'asana'

const https = require('https')

Expand All @@ -18,20 +17,33 @@ export async function run(): Promise<void> {
const github = new GitHub()
await github.performAuth()

console.log(await github.getPR())

const client = asana.Client.create().useAccessToken(
'2/1206483982378697/1208824408454690:c4f53eae40f6660b5ee537081212094a'
//core.getInput('ASANA_PAT')
)
client.users
.me()
.then(user => {
console.log(`Hello, ${user.name}`)
})
.catch(error => {
console.error('Error:', error)
})
const pr = await github.getPR()

const Asana = require('asana')

let client = Asana.ApiClient.instance
let token = client.authentications['token']
token.accessToken = core.getInput('ASANA_PAT')

let tasksApiInstance = new Asana.TasksApi()
let body = {
data: {
name: pr.title,
completed: false,
html_notes: '<body></body>',
is_rendered_as_separator: false,
custom_fields: {
'1200104134002768': '1200104134002769',
'1200104134631161': '1200104134631162'
},
projects: ['1200104507062793']
}
}

// POST - Create a task
const task = await tasksApiInstance.createTask(body, {})

github.updatePRDescription(pr, task)
} catch (error) {
// Fail the workflow run if an error occurs
if (error instanceof Error) core.setFailed(error.message)
Expand Down

0 comments on commit 6c09c2a

Please sign in to comment.