Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function run() {
try {
const issueMessage: string = core.getInput('issue-message');
const prMessage: string = core.getInput('pr-message');
if (!issueMessage && !prMessage) {
throw new Error(
'Action must have at least one of issue-message or pr-message set'
);
}
// Get client and context
const client: github.GitHub = new github.GitHub(
core.getInput('repo-token', {required: true})
);
const context = github.context;
if (context.payload.action !== 'opened') {
console.log('No issue or PR was opened, skipping');
return;
}
// Do nothing if its not a pr or issue
const isIssue: boolean = !!context.payload.issue;
if (!isIssue && !context.payload.pull_request) {
console.log(
'The event that triggered this action was not a pull request or issue, skipping.'
);
return;
}
// Do nothing if its not their first contribution
// Filter matching commands by whether or not to allow edits
if (github.context.payload.action == "edited") {
configMatches = configMatches.filter(function(cmd) {
return cmd.allow_edits;
});
core.debug(`Config matches on 'allow_edits': ${inspect(configMatches)}`);
if (configMatches.length == 0) {
core.info(
`Command '${commentWords[0]}' is not configured to allow edits.`
);
return;
}
}
// Set octokit clients
const octokit = new github.GitHub(inputs.token);
const reactionOctokit = inputs.reactionToken
? new github.GitHub(inputs.reactionToken)
: new github.GitHub(inputs.token);
// At this point we know the command is registered
// Add the "eyes" reaction to the comment
if (inputs.reactions)
await addReaction(
reactionOctokit,
github.context.repo,
commentId,
"eyes"
);
// Get the actor permission
const actorPermission = await getActorPermission(
configMatches = configMatches.filter(function(cmd) {
return cmd.allow_edits;
});
core.debug(`Config matches on 'allow_edits': ${inspect(configMatches)}`);
if (configMatches.length == 0) {
core.info(
`Command '${commentWords[0]}' is not configured to allow edits.`
);
return;
}
}
// Set octokit clients
const octokit = new github.GitHub(inputs.token);
const reactionOctokit = inputs.reactionToken
? new github.GitHub(inputs.reactionToken)
: new github.GitHub(inputs.token);
// At this point we know the command is registered
// Add the "eyes" reaction to the comment
if (inputs.reactions)
await addReaction(
reactionOctokit,
github.context.repo,
commentId,
"eyes"
);
// Get the actor permission
const actorPermission = await getActorPermission(
octokit,
github.context.repo,
export async function createModelLabel (name: string) {
// Create new label if it doesn't exist
try {
await octokit.issues.createLabel({
...context.repo,
name,
color: colorHash.hex(name)
})
} catch (err) {
core.debug(err.message)
// TODO: Handle errors. If this throws because the label
// already exists, ignore the error. Else, throw.
}
}
async function run() {
try {
// Get authenticated GitHub client (Ocktokit): https://github.com/actions/toolkit/tree/master/packages/github#usage
const github = new GitHub(process.env.GITHUB_TOKEN);
// Get owner and repo from context of payload that triggered the action
const { owner, repo } = context.repo;
// Get the inputs from the workflow file: https://github.com/actions/toolkit/tree/master/packages/core#inputsoutputs
const tagName = core.getInput('tag_name', { required: true });
// This removes the 'refs/tags' portion of the string, i.e. from 'refs/tags/v1.10.15' to 'v1.10.15'
const tag = tagName.replace('refs/tags/', '');
const releaseName = core.getInput('release_name', { required: true }).replace('refs/tags/', '');
const body = core.getInput('body', { required: false });
const draft = core.getInput('draft', { required: false }) === 'true';
const prerelease = core.getInput('prerelease', { required: false }) === 'true';
// Create a release
// API Documentation: https://developer.github.com/v3/repos/releases/#create-a-release
// Octokit Documentation: https://octokit.github.io/rest.js/#octokit-routes-repos-create-release
const createReleaseResponse = await github.repos.createRelease({
owner,
return this.hooks.save(async () => {
// Create the new issue
const newIssue = await octokit.issues.create({
...context.repo,
title: `[${this.name}]: ${id}`,
body: Model.jsonToBody(data),
labels: [this.name]
})
// Return the new instance
return new Instance(this, {
...data,
created_at: newIssue.data.created_at,
issue_number: newIssue.data.number
})
}, opts)
}, opts)
export default async function runEvent () {
// Create the ActionRecord instance
const actionRecord = new ActionRecord()
// Register the models, setting actionRecord.models
await registerModels(actionRecord)
// Find the event function
const eventFn = findEventFunction(context.eventName)
if (eventFn) {
// Run it
return eventFn(actionRecord)
}
}
// External Dependencies
const fs = require('fs');
const gh = require('@actions/github');
const commits = gh.event.commits.filter(c => c.distinct);
const FILES = [];
const FILES_MODIFIED = [];
const FILES_ADDED = [];
const FILES_DELETED = [];
commits.forEach(commit => {
FILES.push(...commit.modified, ...commit.added);
FILES_MODIFIED.push(...commit.modified);
FILES_ADDED.push(...commit.added);
FILES_DELETED.push(...commit.removed);
});
fs.writeFileSync(`${process.env.HOME}/files.json`, JSON.stringify(FILES), 'utf-8');
fs.writeFileSync(`${process.env.HOME}/files_modified.json`, JSON.stringify(FILES_MODIFIED), 'utf-8');
fs.writeFileSync(`${process.env.HOME}/files_added.json`, JSON.stringify(FILES_ADDED), 'utf-8');
const run = async () => {
try {
const organization = core.getInput('organization', { required: true })
const teamName = core.getInput('team')
const comment = core.getInput('comment')
const { ACCESS_TOKEN } = process.env
if (!ACCESS_TOKEN)
return core.setFailed('ENV required and not supplied: ACCESS_TOKEN')
const { payload, sha } = github.context
const { repository } = payload
const octokit = new github.GitHub(ACCESS_TOKEN)
const commit = await octokit.git.getCommit({
owner: repository.owner.login,
repo: repository.name,
commit_sha: sha
})
const isMergeCommit = commit.data.parents.length > 1
if (!isMergeCommit) return
const {
data: [pullRequest]
} = await octokit.repos.listPullRequestsAssociatedWithCommit({
owner: repository.owner.login,
repo: repository.name,
commit_sha: sha
async function main() {
const AsyncFunction = Object.getPrototypeOf(async () => {}).constructor
const token = core.getInput('github-token', {required: true})
const debug = core.getInput('debug')
const userAgent = core.getInput('user-agent')
const previews = core.getInput('previews')
const opts: {[key: string]: any} = {}
if (debug === 'true') opts.log = console
if (userAgent != null) opts.userAgent = userAgent
if (previews != null) opts.previews = previews.split(',')
const client = new GitHub(token, opts)
const script = core.getInput('script', {required: true})
const fn = new AsyncFunction('require', 'github', 'context', script)
const result = await fn(require, client, context)
let encoding = core.getInput('result-encoding')
encoding = encoding ? encoding : 'json'
let output
switch (encoding) {
case 'json':
output = JSON.stringify(result)
break
case 'string':
output = String(result)
break