-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add getFileRevision method to GitHubClient for retrieving file content by ref * Add concurrency to workflow and refactor GitHub file retrieval method * Add code search functionality and sample script for GitHub integration * Remove env.secrets section and add defDiff documentation for comparing data * Add language specification for `def` in context documentation. * Add GitHub querying support with helper functions and examples
- Loading branch information
Showing
23 changed files
with
762 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
--- | ||
title: GitHub | ||
description: Support for querying GitHub | ||
sidebar: | ||
order: 50 | ||
--- | ||
|
||
The `github` provides several helper function to query github. It also provides the connection information for more advanced usage. | ||
|
||
## Configuration | ||
|
||
The `github` configuration is automatically sniffed from the environment and git. | ||
|
||
The GitHub token is read from the `GITHUB_TOKEN` environment variable. Some queries might work without authentication for public repositories. | ||
|
||
### GitHub CodeSpaces | ||
|
||
In a GitHub CodeSpace, the `GITHUB_TOKEN` is automatically provisioned. | ||
|
||
### GitHub Actions | ||
|
||
In GitHub Actions, you might will to add permissions to the | ||
workspace to access workflow logs and pull requests. You also need to pass the `secret.GITHUB_TOKEN` to the genaiscript script run. | ||
|
||
```yml title="genai.yml" 'actions: read' 'GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}' | ||
permissions: | ||
contents: read | ||
actions: read | ||
pull-requests: read # or write if you plan to create comments | ||
... | ||
- run: npx --yes genaiscript ... | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
... | ||
``` | ||
|
||
## Functions | ||
|
||
### Issues | ||
|
||
You can query issues and issue comments using `listIssues`, `listIssueComments`. | ||
|
||
```js | ||
const issues = await github.listIssues({ per_page: 5 }) | ||
console.log(issues.map((i) => i.title)) | ||
|
||
// use number! | ||
const issueComments = await github.listIssueComments(issues[0].number) | ||
console.log(issueComments) | ||
``` | ||
|
||
### Pull Requests | ||
|
||
You can query pull requests and pull request reviews comments using `listPullRequests`, `listPullRequestReviewComments`. | ||
|
||
```js | ||
const prs = await github.listPullRequests({ pre_page: 5 }) | ||
console.log(prs.map((i) => i.title)) | ||
|
||
// use number! | ||
const prcs = await github.listPullRequestReviewComments(prs[0].number) | ||
console.log(prcs.map((i) => i.body)) | ||
``` | ||
|
||
In GitHub Actions, you need to give the `pull-request: read` permission. | ||
|
||
### Workflow runs | ||
|
||
Access the log of workflow runs to analyze failures. | ||
|
||
```js | ||
// list runs | ||
const runs = await github.listWorkflowRuns("build.yml", { per_page: 5 }) | ||
console.log(runs.map((i) => i.status)) | ||
|
||
const jobs = await github.listWorkflowJobs(runs[0].id) | ||
// redacted job log | ||
console.log(jobs[0].content) | ||
``` | ||
|
||
In GitHub Actions, you need to give the `actions: read` permission. | ||
|
||
### Search Code | ||
|
||
Use `searchCode` for a code search on the default branch in the same repo. | ||
|
||
```js | ||
const res = await github.searchCode("HTMLToText") | ||
console.log(res) | ||
``` | ||
|
||
### Get file content | ||
|
||
Gets the file content for a given ref, tag or commit sha. | ||
|
||
```js | ||
const pkg = await github.getFile("package.json", "main") | ||
console.log(pkg.content.slice(0, 50) + "...") | ||
``` |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.