Skip to content
This repository has been archived by the owner on Aug 30, 2023. It is now read-only.

Commit

Permalink
chore: move to Typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
Shesekino committed Mar 16, 2020
1 parent 8b4fbf6 commit a7b1478
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 32 deletions.
66 changes: 35 additions & 31 deletions dist/index.js

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

21 changes: 21 additions & 0 deletions package-lock.json

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

8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"license": "MIT",
"main": "dist/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"build": "tsc"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -32,5 +33,10 @@
"fail": [
"@semantic-release/github"
]
},
"devDependencies": {
"@types/needle": "^2.0.4",
"@types/node": "^13.9.1",
"typescript": "^3.8.3"
}
}
43 changes: 43 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import * as fs from 'fs';
import * as needle from 'needle';

const GITHUB_TOKEN = process.env.GITHUB_TOKEN;

const eventName = process.env.GITHUB_EVENT_NAME;
if (eventName !== 'pull_request') {
process.exit(1);
}

const eventPath = process.env.GITHUB_EVENT_PATH;
if (!eventPath) {
console.log('Couldn\'t find the event file path.');
process.exit(1);
}

const eventData = fs.readFileSync(eventPath, 'utf8');
const eventObj = JSON.parse(eventData);
console.log(eventObj);

async function postComment(issueUrl: string): Promise<void> {
const url = `${issueUrl}/comments`;
const payload = {
body: 'There\'s butter on my face!',
};
const options = {
json: true,
compressed: true,
headers: {
Authorization: 'token ' + GITHUB_TOKEN,
},
};

try {
await needle('post', url, payload, options);
console.log('huzzah!');
} catch (err) {
console.log('I have no idea what I\'m doing');
}
}

const issueUrl = eventObj.pull_request.issue_url;
postComment(issueUrl);
19 changes: 19 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"compilerOptions": {
"outDir": "./dist",
"incremental": true,
"target": "es2018",
"module": "commonjs",
"sourceMap": true,
"pretty": true,
"importHelpers": true,
"strict": true,
"noImplicitAny": true,
"noUnusedLocals": true,
"resolveJsonModule": true,
"noImplicitReturns": true
},
"include": [
"./src/**/*"
]
}

0 comments on commit a7b1478

Please sign in to comment.