snippets_js
Integration
New integration from credential
const githubClient = yepcode.integration.github('credential-slug')
New integration from plain authentication data
const { Octokit } = require("octokit");
const githubClient = new Octokit({ auth: 'your-personal-token' });
Create a Repository
Create repository
const response = await githubClient.rest.repos
.createForAuthenticatedUser({
name: 'your-new-repository-name',
description: `Some description`,
private: true,
auto_init: true
// other props
})
console.log(`Created repository ${response.data.full_name}`);
Delete a Repository
Delete repository
const response = await githubClient.rest.repos
.delete({
owner: 'repository-owner',
repo: 'repository-name',
})
console.log("Deleted repository");
Get a File from Repository
Get file from repository
const response = await githubClient.rest.repos
.getContent({
mediaType: {
format: "raw",
},
owner: 'repository-owner',
repo: 'repository-name',
path: 'path-to-file',
})
console.log(response.data);
Get Commits from Repository
Get commits from repository
const response = await githubClient.rest.repos
.listCommits({
owner: 'repository-owner',
repo: 'repository-name',
per_page: page-size,
page: page-number,
})
const commits = response.data;
commits.forEach((commit) => console.log(`Found commit! ${commit.commit.message}`));
Get Issues from Repository
Get issues from repository
const response = await githubClient.rest.issues
.listForRepo({
owner: 'repository-owner',
repo: 'repository-name',
per_page: page-size,
page: page-number,
state: "open",
})
const issues = response.data;
issues.forEach((issue) => console.log(`Found issue! ${issue.title}`));
Create Issue in a Repository
Create issue in a repository
const response = await githubClient.rest.issues
.create({
owner: 'repository-owner',
repo: 'repository-name',
title: 'issue-title',
body: 'issue-body',
})
console.log(`Created issue! See it here: ${response.data.html_url}`);
Use GraphQL
Use GraphQL
const response = await githubClient
.graphql(
`
query theQuery($owner: String!, $repo: String!) {
theQuery(owner: $owner, name: $repo) {
// the query content
}
}
`,
{
owner: 'repository-owner',
repo: 'repository-name',
}
)