How to use the @actions/github.context.sha 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 ziishaned / jest-reporter-action / index.js View on Github external
const main = async () => {
  const repoName = context.repo.repo;
  const repoOwner = context.repo.owner;
  const githubToken = core.getInput("github-token");
  const testCommand = core.getInput("test-command") || "npx jest";

  const githubClient = new GitHub(githubToken);
  const commitPRs = await githubClient.repos.listPullRequestsAssociatedWithCommit(
    {
      repo: repoName,
      owner: repoOwner,
      commit_sha: context.sha
    }
  );
  const prNumber = commitPRs.data[0].number;

  const codeCoverage = execSync(testCommand).toString();
  let coveragePercentage = execSync(
    "npx coverage-percentage ./coverage/lcov.info --lcov"
  ).toString();
  coveragePercentage = parseFloat(coveragePercentage).toFixed(2);

  const commentBody = `<p>Total Coverage: <code>${coveragePercentage}</code></p>
<details><summary>Coverage report</summary>
<p>
</p><pre>${codeCoverage}</pre>
<p></p>
</details>`;

@actions/github

Actions github lib

MIT
Latest version published 1 year ago

Package Health Score

88 / 100
Full package analysis