Skip to content

Commit

Permalink
Updated actions script :brick:
Browse files Browse the repository at this point in the history
  • Loading branch information
ankur12-1610 committed Jan 5, 2022
1 parent af47fd5 commit e297f77
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 164 deletions.
29 changes: 12 additions & 17 deletions bin/activity.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,30 +40,25 @@ function run() {
const { pull_request } = context.payload;
const payload = context.payload.pull_request;
const author = payload.user.login;
const creator = context.payload.sender.login;
const tag_text = (TAG_AUTHOR ? `@` + author + ` ` : null);
const assignee = (ASSIGN_TO_AUTHOR ? author : null);
const client = new github.getOctokit(GITHUB_TOKEN);
//get no of prs created by author
const prs_by_author = yield octokit.rest.pulls.list({
owner: author,
repo: context.repo.repo,
client: client,
sender: author,
state: 'all'
});
const prs_by_author_count = prs_by_author.data.length;
console.log(`${prs_by_author_count} PRs created by ${author}`);
//comment to first timers
let first_timers_comment = '';
if (prs_by_author_count > 1) {
first_timers_comment = FIRST_TIMERS_MESSAGE ? FIRST_TIMERS_MESSAGE : `Thanks for the PR!`;
}
//comment on PR
yield octokit.rest.issues.createComment(Object.assign(Object.assign({}, context.repo), { issue_number: pull_request.number, body: tag_text + COMMENT_TEXT + gif + first_timers_comment, id: payload.number.toString() }));
yield octokit.rest.issues.createComment(Object.assign(Object.assign({}, context.repo), { issue_number: pull_request.number, body: tag_text + COMMENT_TEXT + gif, id: payload.number.toString() }));
//assign PR to its author
yield octokit.rest.issues.addAssignees(Object.assign(Object.assign({}, context.repo), { issue_number: pull_request.number, assignees: assignee }));
//add reaction to PR
yield octokit.rest.reactions.createForIssue(Object.assign(Object.assign({}, context.repo), { repo: context.repo.repo, issue_number: pull_request.number, content: PR_REACTION, owner: context.repo.owner }));
//for first timers
const pulls = yield octokit.rest.pulls.list(Object.assign(Object.assign({}, context.repo), { state: 'all', sort: 'created', direction: 'desc' }));
console.log('Checking...');
if (pulls.data.length === 1) {
console.log('First pull request!');
yield octokit.rest.issues.createComment(Object.assign(Object.assign({}, context.repo), { issue_number: pull_request.number, body: FIRST_TIMERS_MESSAGE, id: payload.number.toString() }));
}
else {
console.log('Not first pull request');
}
}
catch (e) {
core.error(e);
Expand Down
122 changes: 0 additions & 122 deletions bin/ftimers.js

This file was deleted.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"@actions/github": "^5.0.0",
"@actions/io": "^1.0.0",
"@actions/tool-cache": "^1.7.1",
"@octokit/endpoint": "^6.0.12",
"@types/axios": "^0.14.0",
"@types/node": "^17.0.5",
"@vercel/ncc": "^0.33.1",
Expand Down
47 changes: 23 additions & 24 deletions src/activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const core = require('@actions/core')
const github = require('@actions/github')
const camelCase = require('camelcase')
import axios, { AxiosInstance, AxiosResponse } from 'axios'
import { isUnparsedSource } from 'typescript'

declare module 'axios' {
interface AxiosResponse<T = any> extends Promise<T> {}
Expand Down Expand Up @@ -34,33 +35,11 @@ export async function run() {
const { pull_request } = context.payload
const payload = context.payload.pull_request
const author = payload.user.login
const creator = context.payload.sender.login
const tag_text = (TAG_AUTHOR ? `@` + author + ` ` : null)
const assignee = (ASSIGN_TO_AUTHOR ? author : null)

//get no of prs created by author
const prs_by_author = await octokit.rest.pulls.list({
owner: author,
repo: context.repo.repo,
client: octokit.client,
sender: author,
state: 'all'
})
const prs_by_author_count = prs_by_author.data.length

console.log(`${prs_by_author_count} PRs created by ${author}`)

//comment to first timers
if (prs_by_author_count > 1) {
const first_timers_comment = FIRST_TIMERS_MESSAGE ? FIRST_TIMERS_MESSAGE : `Thanks for the PR!`
await octokit.rest.issues.createComment({
...context.repo,
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pull_request.number,
body: first_timers_comment
})
}


//comment on PR
await octokit.rest.issues.createComment({
...context.repo,
Expand All @@ -85,6 +64,26 @@ export async function run() {
owner: context.repo.owner
})

//for first timers
const pulls = await octokit.rest.pulls.list({
...context.repo,
state: 'all',
sort: 'created',
direction: 'desc',
})
console.log('Checking...')
if( pulls.data.length === 1 ) {
console.log('First pull request!')
await octokit.rest.issues.createComment({
...context.repo,
issue_number: pull_request.number,
body: FIRST_TIMERS_MESSAGE,
id: payload.number.toString()
})
} else {
console.log('Not first pull request')
}

} catch (e) {
core.error(e)
core.setFailed((e as Error).message)
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
before-after-hook "^2.2.0"
universal-user-agent "^6.0.0"

"@octokit/endpoint@^6.0.1":
"@octokit/endpoint@^6.0.1", "@octokit/endpoint@^6.0.12":
version "6.0.12"
resolved "https://registry.yarnpkg.com/@octokit/endpoint/-/endpoint-6.0.12.tgz#3b4d47a4b0e79b1027fb8d75d4221928b2d05658"
integrity sha512-lF3puPwkQWGfkMClXb4k/eUT/nZKQfxinRWJrdZaJO85Dqwo/G0yOC434Jr2ojwafWJMYqFGFa5ms4jJUgujdA==
Expand Down

0 comments on commit e297f77

Please sign in to comment.