How to use the actions-toolkit.Toolkit.run function in actions-toolkit

To help you get started, weā€™ve selected a few actions-toolkit examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github JasonEtco / create-an-issue / index.js View on Github external
const core = require('@actions/core')
const { Toolkit } = require('actions-toolkit')
const fm = require('front-matter')
const nunjucks = require('nunjucks')
const dateFilter = require('nunjucks-date-filter')

function listToArray (list) {
  if (!list) return []
  return Array.isArray(list) ? list : list.split(', ')
}

Toolkit.run(async tools => {
  const template = core.getInput('filename') || '.github/ISSUE_TEMPLATE.md'
  const assignees = core.getInput('assignees')
  const env = nunjucks.configure({ autoescape: false })
  env.addFilter('date', dateFilter)

  const templateVariables = {
    ...tools.context,
    date: Date.now()
  }

  // Get the file
  tools.log.debug('Reading from file', template)
  const file = tools.getFile(template)

  // Grab the front matter as JSON
  const { attributes, body } = fm(file)
github alex-page / add-new-issue-project / index.js View on Github external
const { Toolkit } = require( 'actions-toolkit' );


Toolkit.run( async ( tools ) => {
  try {
    const { action, issue } = tools.context.payload;
    if( action !== 'opened' ){
      tools.exit.neutral( `Event ${ action } is not supported by this action.` )
    }

    // Get the arguments
    const projectName = tools.arguments._[ 0 ];
    const columnName  = tools.arguments._[ 1 ];

    const secret = process.env.GH_PAT ? process.env.GH_PAT : process.env.GITHUB_TOKEN;

    // Fetch the column ids and names
    const { resource } = await tools.github.graphql({
      query: `query {
        resource( url: "${ issue.html_url }" ) {
github JasonEtco / actions-toolkit / bin / template / index.js View on Github external
const { Toolkit } = require('actions-toolkit')

// Run your GitHub Action!
Toolkit.run(async tools => {
  tools.exit.success('We did it!')
})
github iam4x / now-deploy-preview-comment / index.js View on Github external
deployedCommit: process.env.GITHUB_SHA,
  deployedBranch: process.env.GITHUB_REF,
};

if (!actionConfig.zeitToken) {
  throw new Error(`ZEIT_TOKEN environment variable is not set`);
}

const zeitAPIClient = axios.create({
  baseURL: 'https://api.zeit.co',
  headers: { Authorization: `Bearer ${actionConfig.zeitToken}` },
  params: { teamId: actionConfig.teamId },
});

// Run your GitHub Action!
Toolkit.run(async tools => {
  function fetchLastDeployment(params) {
    return zeitAPIClient
      .get('/v4/now/deployments', { params })
      .then(({ data }) => data.deployments[0]);
  }

  const strategies = [
    fetchLastDeployment({ 'meta-commit': actionConfig.deployedCommit }),
    fetchLastDeployment({ 'meta-branch': actionConfig.deployedBranch }),
    fetchLastDeployment({ limit: 1 }),
  ];

  let deploymentUrl;
  let deploymentCommit;
  let deploymentProjectName;
github atom / github / actions / auto-sprint / index.js View on Github external
const {Toolkit} = require('actions-toolkit');
const {withDefaults} = require('actions-toolkit/lib/graphql');

Toolkit.run(async tools => {
  // Re-authenticate with the correct secret.
  tools.github.graphql = withDefaults(process.env.GRAPHQL_TOKEN);

  // Ensure that the actor of the triggering action belongs to the core team
  const actorLogin = tools.context.actor;
  const teamResponse = await tools.github.graphql(`
    query {
      organization(login: "atom") {
        team(slug: "github-package") {
          members(first: 100) {
            nodes {
              login
            }
          }
        }
      }
github JasonEtco / activity-box / index.js View on Github external
return `ā—ļø ${capitalize(item.payload.action)} issue #${
      item.payload.issue.number
    } in ${item.repo.name}`
  },
  PullRequestEvent: item => {
    const emoji = item.payload.action === 'opened' ? 'šŸ’Ŗ' : 'āŒ'
    const line = item.payload.pull_request.merged
      ? 'šŸŽ‰ Merged'
      : `${emoji} ${capitalize(item.payload.action)}`
    return `${line} PR #${item.payload.pull_request.number} in ${
      item.repo.name
    }`
  }
}

Toolkit.run(
  async tools => {
    const { GIST_ID, GH_USERNAME, GH_PAT } = process.env

    // Get the user's public events
    tools.log.debug(`Getting activity for ${GH_USERNAME}`)
    const events = await tools.github.activity.listPublicEventsForUser({
      username: GH_USERNAME,
      per_page: 100
    })
    tools.log.debug(
      `Activity for ${GH_USERNAME}, ${events.data.length} events found.`
    )

    const content = events.data
      // Filter out any boring activity
      .filter(event => serializers.hasOwnProperty(event.type))
github JasonEtco / smee-action / entrypoint.js View on Github external
const { Toolkit } = require('actions-toolkit')
const fetch = require('node-fetch')
const hash = require('object-hash')

Toolkit.run(async tools => {
  // Serialize payload object
  const payload = {
    ...tools.context.payload,
    'smee-action': {
      action: tools.context.action,
      actor: tools.context.actor,
      event: tools.context.event,
      sha: tools.context.sha,
      ref: tools.context.ref,
      workflow: tools.context.workflow
    }
  }

  // Serialize headers
  const headers = {
    'X-GitHub-Event': tools.context.event,
github vijaykramesh / pr-lint-action / index.js View on Github external
const { Toolkit } = require('actions-toolkit')
const getConfig = require('./utils/config')

const CONFIG_FILENAME = 'pr-lint.yml'

const defaults = {
  projects: ['PROJ'],
  check_title: true,
  check_branch: false,
  check_commits: false,
  ignore_case: false
}

Toolkit.run(
  async tools => {
    const { repository, pull_request } = tools.context.payload

    const repoInfo = {
      owner: repository.owner.login,
      repo: repository.name,
      ref: pull_request.head.ref
    }

    const config = {
      ...defaults,
      ...(await getConfig(tools.github, CONFIG_FILENAME, repoInfo))
    }

    const title = config.ignore_case ?
      pull_request.title.toLowerCase() :
github SAP / cloud-commerce-spartacus-storefront / .github / api-extractor-action / index.js View on Github external
const { Toolkit } = require('actions-toolkit');
const diff = require('diff-lines');
const normalizeNewline = require('normalize-newline');

Toolkit.run(
  async tools => {
    const owner = tools.context.payload.repository.owner.login;
    const repo = tools.context.payload.repository.name;

    const response = await tools.github.pulls.list({
      owner,
      repo,
      head: 'SAP:' + tools.context.payload.ref.replace('refs/heads/', ''),
    });

    const relatedPullRequests = response.data;

    if (relatedPullRequests.length === 0) {
      return;
    }

actions-toolkit

A toolkit for building GitHub Actions in Node.js

MIT
Latest version published 4 years ago

Package Health Score

53 / 100
Full package analysis