How to use the @actions/github.context function in @actions/github

To help you get started, we’ve selected a few @actions/github 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 actions / first-interaction / src / main.ts View on Github external
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
github grafana / grafana / .github / actions / deploy-storybook / index.js View on Github external
const core = require('@actions/core');
const github = require('@actions/github');

try {
  console.log(github.context.payload.pull_request);
} catch (error) {
  core.setFailed(error.message);
}
github mooyoul / tslint-actions / index.ts View on Github external
(async () => {
  const ctx = github.context as Context;

  const configFileName = core.getInput("config") || "tslint.json";
  const projectFileName = core.getInput("project");
  const pattern = core.getInput("pattern");
  const ghToken = core.getInput("token");

  if (!projectFileName && !pattern) {
    core.setFailed("tslint-actions: Please set project or pattern input");
    return;
  }

  if (!ghToken) {
    core.setFailed("tslint-actions: Please set token");
    return;
  }
github svenstaro / upload-release-action / src / main.ts View on Github external
async function run() {
    try {
        const token = core.getInput('repo_token', { required: true });
        const file = core.getInput('file', { required: true });
        const asset_name = core.getInput('asset_name', { required: true });
        const tag = core.getInput('tag', { required: true }).replace("refs/tags/", "");
        const overwrite = core.getInput('overwrite');

        if (!fs.existsSync(file)) {
            core.setFailed(`File ${file} wasn't found.`);
        }

        const octokit = new github.GitHub(token);
        const context = github.context;

        const release = await get_release_by_tag(tag, octokit, context);
        await upload_to_release(release, file, asset_name, tag, overwrite, octokit, context);
    } catch (error) {
        core.setFailed(error.message);
    }
}
github johnbillion / wp-crontrol / .github / workflows / changelog.js View on Github external
async function run() {
	const api = new github.GitHub(myToken);

	const { data: releases } = await api.repos.listReleases( github.context.repo );

	let published = releases.filter( release =>
		! release.draft && ! release.prerelease
	);

	let sorted = published.sort( ( a, b ) =>
		semver.rcompare( semver.coerce( a.tag_name ), semver.coerce( b.tag_name ) )
	);

	let changelog = sorted.reduce( ( changelog, release ) =>
		`${changelog}

### ${release.tag_name} ###

${release.body}`
	, '## Changelog ##' );
github cli / cli / .github / actions / update-changelog / src / index.ts View on Github external
async function main() {
  const title =
    github.context.payload &&
    github.context.payload.pull_request &&
    github.context.payload.pull_request.title
  const { changelog, sha } = await getChangelog()
  const updatedChangelog = { ...changelog, draft: [title, ...changelog.draft] }
  await commitChangelog(updatedChangelog, sha)
}
github r-lib / actions / goodpractice / src / main.ts View on Github external
async function run() {
  try {
    const token: string = core.getInput("repo-token", { required: true });

    const octokit = new github.GitHub(token);

    const context = github.context;

    const check = await octokit.checks.create({
      ...context.repo,
      name: "goodpractice",
      head_sha: context.sha,
      status: "in_progress"
    });

    await exec.exec("Rscript", [
      "-e",
      "x <- goodpractice::goodpractice()",
      "-e",
      'capture.output(print(x), file = ".goodpractice")'
    ]);

    const results = fs.readFileSync(".goodpractice").toString();
github deliverybot / helm / index.js View on Github external
async function status(state) {
  try {
    const context = github.context;
    const deployment = context.payload.deployment;
    const token = core.getInput("token");
    if (!token || !deployment) {
      core.debug("not setting deployment status");
      return;
    }

    const client = new github.GitHub(token);
    const url = `https://github.com/${context.repo.owner}/${context.repo.repo}/commit/${context.sha}/checks`;

    await client.repos.createDeploymentStatus({
      ...context.repo,
      deployment_id: deployment.id,
      state,
      log_url: url,
      target_url: url,
github grafana / grafana / .github / actions / verify-deploy-storybook / index.js View on Github external
const core = require('@actions/core');
const github = require('@actions/github');

const DEPLOY_STORYBOOK_LABEL = 'deploy-storybook';

try {
  const pullRequest = github.context.payload.pull_request;
  let shouldDeploy = false;
  if(pullRequest && pullRequest.labels) {
     shouldDeploy = !!(pullRequest.labels.find(l => l.name === DEPLOY_STORYBOOK_LABEL))
  }
  core.setOutput('shouldDeploy', shouldDeploy.toString());
} catch (error) {
  core.setFailed(error.message);
}
github kentaro-m / auto-assign-action / src / run.ts View on Github external
export async function run() {
  try {
    const token = core.getInput('repo-token', { required: true })
    const configPath = core.getInput('configuration-path', {
      required: true,
    })

    const client = new github.GitHub(token)
    const { repo, sha } = github.context
    const config = await utils.fetchConfigurationFile(client, {
      owner: repo.owner,
      repo: repo.repo,
      path: configPath,
      ref: sha,
    })

    await handler.handlePullRequest(client, github.context, config)
  } catch (error) {
    core.setFailed(error.message)
  }
}

@actions/github

Actions github lib

MIT
Latest version published 1 year ago

Package Health Score

88 / 100
Full package analysis