Skip to main content

github.github

Home > @runlightyear/github > GitHub

GitHub class

Connector to the GitHub API

Signature:
declare class GitHub extends RestConnector 

Extends:

RestConnector

Example 1

On push

import { GitHub } from "@runlightyear/github";

GitHub.onPush({
name: "onPush",
title: "On Push",
run: async ({ data, auths }) => {
console.log("Push data: ", data);
},
});

Example 2

On issue opened

import { GitHub } from "@runlightyear/github";
import { SKIPPED } from "@runlightyear/lightyear";

GitHub.onIssues({
name: "onIssueOpened",
title: "On Issue Opened",
run: async ({ data, auths }) => {
if (data.action !== "opened") {
throw SKIPPED;
}
console.log("Issue opened:", data.issue);
},
});

Example 3

On workflow run completed

import { GitHub } from "@runlightyear/github";
import { SKIPPED } from "@runlightyear/lightyear";

GitHub.onWorkflowRun({
name: "onWorkflowRunComplete",
title: "On Workflow Run Complete",
run: async ({ data, auths }) => {
console.log("Workflow run data: ", data);
if (data.action !== "completed") {
throw SKIPPED;
}
console.log("Workflow run completed:", data);
},
});

Example 4

Create an issue

import { defineAction } from "@runlightyear/lightyear";
import { GitHub } from "@runlightyear/github";

defineAction({
name: "createIssue",
title: "Create Issue",
apps: ["github"],
variables: [
{
name: "owner",
description:
"The account owner of the repository. The name is not case sensitive.",
},
{
name: "repo",
description:
"The name of the repository without the .git extension. The name is not case sensitive.",
},
"title",
],
run: async ({ auths, variables }) => {
const github = new GitHub({
auth: auths.github,
});
const response = await github.createIssue({
owner: variables.owner!,
repo: variables.repo!,
title: variables.title!,
});
console.log("Response: ", response.data);
},
});

Example 5

Assign an issue

import { defineAction } from "@runlightyear/lightyear";
import { GitHub } from "@runlightyear/github";

defineAction({
name: "assignIssue",
title: "Assign Issue",
apps: ["github"],
variables: [
{
name: "owner",
description:
"The account owner of the repository. The name is not case sensitive.",
},
{
name: "repo",
description:
"The name of the repository without the .git extension. The name is not case sensitive.",
},
"issueNumber",
"assignee",
],
run: async ({ auths, variables }) => {
const github = new GitHub({
auth: auths.github,
});
const result = await github.updateIssue({
owner: variables.owner!,
repo: variables.repo!,
issueNumber: parseInt(variables.issueNumber!),
assignees: [variables.assignee!],
});
console.log("Issue: ", result.data);
},
});

Example 6

Label an issue

import { defineAction } from "@runlightyear/lightyear";
import { GitHub } from "@runlightyear/github";

defineAction({
name: "labelIssue",
title: "Label Issue",
apps: ["github"],
variables: [
{
name: "owner",
description:
"The account owner of the repository. The name is not case sensitive.",
},
{
name: "repo",
description:
"The name of the repository without the .git extension. The name is not case sensitive.",
},
"issueNumber",
"label",
],
run: async ({ auths, variables }) => {
const github = new GitHub({
auth: auths.github,
});
const response = await github.updateIssue({
owner: variables.owner!,
repo: variables.repo!,
issueNumber: parseInt(variables.issueNumber!),
labels: [variables.label!],
});
console.log("Response: ", response.data);
},
});

Example 7

Complete an issue

import { defineAction } from "@runlightyear/lightyear";
import { GitHub } from "@runlightyear/github";

defineAction({
name: "completeIssue",
title: "Complete Issue",
apps: ["github"],
variables: [
{
name: "owner",
description:
"The account owner of the repository. The name is not case sensitive.",
},
{
name: "repo",
description:
"The name of the repository without the .git extension. The name is not case sensitive.",
},
"issueNumber",
],
run: async ({ auths, variables }) => {
const github = new GitHub({
auth: auths.github,
});
const response = await github.updateIssue({
owner: variables.owner!,
repo: variables.repo!,
issueNumber: parseInt(variables.issueNumber!),
state: "closed",
stateReason: "completed",
});
console.log("Response: ", response.data);
},
});

Example 8

Compare two commits

import { defineAction } from "@runlightyear/lightyear";
import { GitHub } from "@runlightyear/github";

defineAction({
name: "compareTwoCommits",
title: "Compare Two Commits",
apps: ["github"],
variables: [
{
name: "owner",
description:
"The account owner of the repository. The name is not case sensitive.",
},
{
name: "repo",
description:
"The name of the repository without the .git extension. The name is not case sensitive.",
},
{
name: "basehead",
description:
"The base branch and head branch to compare. This parameter expects the format BASE...HEAD. Both must be branch names in repo. To compare with a branch that exists in a different repository in the same network as repo, the basehead parameter expects the format USERNAME:BASE...USERNAME:HEAD.",
},
],
run: async ({ auths, variables }) => {
const github = new GitHub({
auth: auths.github,
});
const response = await github.compareTwoCommits({
owner: variables.owner!,
repo: variables.repo!,
basehead: variables.basehead!,
});
console.log("Response data:", response.data);
},
});

Example 9

Create a gist

import { defineAction } from "@runlightyear/lightyear";
import { GitHub } from "@runlightyear/github";

defineAction({
name: "createGist",
title: "Create Gist",
apps: ["github"],
run: async ({ auths }) => {
const github = new GitHub({
auth: auths.github,
});
const response = await github.createGist({
description: "Hello World",
files: {
"helloWorld.txt": {
content: "Hello World",
},
},
isPublic: false,
});
console.log("Response data:", response.data);
},
});

Constructors

ConstructorModifiersDescription
(constructor)(props)Constructs a new instance of the GitHub class

Properties

PropertyModifiersTypeDescription
authTypestaticAuthType
OAuthstatictypeof GitHubOAuth

Commit Methods

MethodModifiersDescription
compareTwoCommits(props)Compare two commits

Gist Methods

MethodModifiersDescription
createGist(props)Create a gist

Git Database Methods

MethodModifiersDescription
getTree(props)Get a tree

Helper Methods

MethodModifiersDescription
matchAllCommits(props)staticMatch all commits

Issue Methods

MethodModifiersDescription
createIssue(props)Create an issue
createIssueComment(props)Create an issue comment
updateIssue(props)Update an issue

Listener Methods

MethodModifiersDescription
onCommitComment(props)static

This event occurs when there is activity relating to commit comments.

For activity relating to comments on pull request reviews, use the pull_request_review_comment event. For activity relating to issue comments, use the issue_comment event. For activity relating to discussion comments, use the discussion_comment event.

onCreate(props)static

This event occurs when a Git branch or tag is created.

Note: This event will not occur when more than three tags are created at once.

onDelete(props)static

This event occurs when a Git branch or tag is deleted.

Note: This event will not occur when more than three tags are deleted at once.

onIssueComment(props)static

This event occurs when there is activity relating to a comment on an issue or pull request.

For activity relating to an issue as opposed to comments on an issue, use the issue event. For activity related to pull request reviews or pull request review comments, use the pull_request_review or pull_request_review_comment events. For more information about the different types of pull request comments, see "Working with comments."

onIssues(props)static

This event occurs when there is activity relating to an issue.

For activity relating to a comment on an issue, use the issue_comment event.

onLabel(props)static

This event occurs when there is activity relating to labels.

If you want to receive an event when a label is added to or removed from an issue, pull request, or discussion, use the labeled or unlabeled action type for the issues, pull_request, or discussion events instead.

onMember(props)staticThis event occurs when there is activity relating to collaborators in a repository.
onPullRequest(props)staticOn Pull Request
onPullRequestReview(props)static

This event occurs when there is activity on a pull request.

For activity related to pull request reviews, pull request review comments, pull request comments, or pull request review threads, use the pull_request_review, pull_request_review_comment, issue_comment, or pull_request_review_thread events instead.

onPush(props)static

This event occurs when a commit or tag is pushed.

Note: An event will not be created when more than three tags are pushed at once.

onRepository(props)staticThis event occurs when there is activity relating to repositories.
onStatus(props)staticThis event occurs when the status of a Git commit changes. For example, commits can be marked as error, failure, pending, or success.
onWorkflowDispatch(props)static

This event occurs when a GitHub Actions workflow is manually triggered.

For activity relating to workflow runs, use the workflow_run event.

onWorkflowJob(props)static

This event occurs when there is activity relating to a job in a GitHub Actions workflow.

For activity relating to a workflow run instead of a job in a workflow run, use the workflow_run event.

onWorkflowRun(props)static

This event occurs when there is activity relating to a run of a GitHub Actions workflow.

For activity relating to a job in a workflow run, use the workflow_job event.

Pull Request Methods

MethodModifiersDescription
createPullRequest(props)Create a pull request
updatePullRequest(props)Update a pull request

Repository Methods

MethodModifiersDescription
listOrganizationRepositories(props)List organization repositories
listRepositoriesForAuthenticatedUser(props)List repositories for the authenticated user
listRepositoriesForUser(props)List repositories for a user

Repository Content Methods

MethodModifiersDescription
downloadRepoArchiveTar(props)Download a repository archive (tar)
downloadRepoArchiveZip(props)Download a repository archive (zip)

Search Methods

MethodModifiersDescription
searchIssuesAndPullRequests(props)Search issues and pull requests
searchRepositories(props)Search repositories
searchUsers(props)Search users

Webhook Methods

MethodModifiersDescription
createRepositoryWebhook(props)Create a repository webhook
defineWebhook(props)staticDefine a GitHub repository webhook
deleteRepositoryWebhook(props)Delete a repository webhook
getRepositoryWebhook(props)Get a repository webhook
listRepositoryWebhooks(props)List repository webhooks
pingRepositoryWebhook(props)Ping a repository webhook
testPushRepositoryWebhook(props)Test the push repository webhook
updateRepositoryWebhook(props)Update a repository webhook

Webhook Payload Methods

MethodModifiersDescription
asCommitCommentPayload(data)staticCommit Comment Payload
asCreatePayload(data)staticCreate Payload
asDeletePayload(data)staticDelete Payload
asIssueCommentPayload(data)staticIssue Comment Payload
asIssuesPayload(data)staticIssues Payload
asLabelPayload(data)staticLabel Payload
asMemberPayload(data)staticMember Payload
asPingPayload(data)staticPing Payload
asPullRequestPayload(data)staticPull Request Payload
asPullRequestReviewPayload(data)staticPull Request Review Payload
asPushPayload(data)staticPush Payload
asRepositoryPayload(data)staticRepository Payload
asStatusPayload(data)staticStatus Payload
asWorkflowDispatchPayload(data)staticWorkflow Dispatch Payload
asWorkflowJobPayload(data)staticWorkflow Job Payload
asWorkflowRunPayload(data)staticWorkflow Run Payload

Other Methods

MethodModifiersDescription
getBaseUrl()
getDefaultHeaders()