github.com/nektos/act@v0.2.63/pkg/runner/testdata/actions/node12/node_modules/@actions/github/README.md (about)

     1  # `@actions/github`
     2  
     3  > A hydrated Octokit client.
     4  
     5  ## Usage
     6  
     7  Returns an authenticated Octokit client that follows the machine [proxy settings](https://help.github.com/en/actions/hosting-your-own-runners/using-a-proxy-server-with-self-hosted-runners) and correctly sets GHES base urls. See https://octokit.github.io/rest.js for the API.
     8  
     9  ```js
    10  const github = require('@actions/github');
    11  const core = require('@actions/core');
    12  
    13  async function run() {
    14      // This should be a token with access to your repository scoped in as a secret.
    15      // The YML workflow will need to set myToken with the GitHub Secret Token
    16      // myToken: ${{ secrets.GITHUB_TOKEN }}
    17      // https://help.github.com/en/actions/automating-your-workflow-with-github-actions/authenticating-with-the-github_token#about-the-github_token-secret
    18      const myToken = core.getInput('myToken');
    19  
    20      const octokit = github.getOctokit(myToken)
    21  
    22      // You can also pass in additional options as a second parameter to getOctokit
    23      // const octokit = github.getOctokit(myToken, {userAgent: "MyActionVersion1"});
    24  
    25      const { data: pullRequest } = await octokit.pulls.get({
    26          owner: 'octokit',
    27          repo: 'rest.js',
    28          pull_number: 123,
    29          mediaType: {
    30            format: 'diff'
    31          }
    32      });
    33  
    34      console.log(pullRequest);
    35  }
    36  
    37  run();
    38  ```
    39  
    40  You can also make GraphQL requests. See https://github.com/octokit/graphql.js for the API.
    41  
    42  ```js
    43  const result = await octokit.graphql(query, variables);
    44  ```
    45  
    46  Finally, you can get the context of the current action:
    47  
    48  ```js
    49  const github = require('@actions/github');
    50  
    51  const context = github.context;
    52  
    53  const newIssue = await octokit.issues.create({
    54    ...context.repo,
    55    title: 'New issue!',
    56    body: 'Hello Universe!'
    57  });
    58  ```
    59  
    60  ## Webhook payload typescript definitions
    61  
    62  The npm module `@octokit/webhooks` provides type definitions for the response payloads. You can cast the payload to these types for better type information.
    63  
    64  First, install the npm module `npm install @octokit/webhooks`
    65  
    66  Then, assert the type based on the eventName
    67  ```ts
    68  import * as core from '@actions/core'
    69  import * as github from '@actions/github'
    70  import * as Webhooks from '@octokit/webhooks'
    71  if (github.context.eventName === 'push') {
    72    const pushPayload = github.context.payload as Webhooks.WebhookPayloadPush
    73    core.info(`The head commit is: ${pushPayload.head}`)
    74  }
    75  ```
    76  
    77  ## Extending the Octokit instance
    78  `@octokit/core` now supports the [plugin architecture](https://github.com/octokit/core.js#plugins). You can extend the GitHub instance using plugins. 
    79  
    80  For example, using the `@octokit/plugin-enterprise-server` you can now access enterprise admin apis on GHES instances.
    81  
    82  ```ts
    83  import { GitHub, getOctokitOptions } from '@actions/github/lib/utils'
    84  import { enterpriseServer220Admin } from '@octokit/plugin-enterprise-server'
    85  
    86  const octokit = GitHub.plugin(enterpriseServer220Admin)
    87  // or override some of the default values as well 
    88  // const octokit = GitHub.plugin(enterpriseServer220Admin).defaults({userAgent: "MyNewUserAgent"})
    89  
    90  const myToken = core.getInput('myToken');
    91  const myOctokit = new octokit(getOctokitOptions(token))
    92  // Create a new user
    93  myOctokit.enterpriseAdmin.createUser({
    94    login: "testuser",
    95    email: "testuser@test.com",
    96  });
    97  ```