Skip to content

Commit

Permalink
add wrapper to list releases
Browse files Browse the repository at this point in the history
  • Loading branch information
pelikhan committed Feb 4, 2025
1 parent e7043f1 commit a54497c
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 7 deletions.
14 changes: 12 additions & 2 deletions docs/src/content/docs/reference/scripts/github.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ description: Support for querying GitHub
sidebar:
order: 50
---
import { PackageManagers } from 'starlight-package-managers'

import { PackageManagers } from "starlight-package-managers"

The `github` module provides several helper functions to query GitHub, along with the connection information for more advanced usage.

## Configuration

The `github` configuration is automatically detected 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.
- The GitHub token is read from the `GITHUB_TOKEN` environment variable. Some queries might work without authentication for public repositories.

### GitHub CodeSpaces

Expand Down Expand Up @@ -136,6 +137,15 @@ const branches = await github.listBranches()
console.log(branches)
```

### Releases

List the releases on the repository using `listReleases`.

```js
const releases = await github.listReleases()
console.log(releases)
```

## Octokit access

Utilize [octokit](https://www.npmjs.com/package/octokit) to access the full GitHub APIs.
Expand Down
14 changes: 14 additions & 0 deletions packages/core/src/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,20 @@ export class GitHubClient implements GitHub {
return res
}

async listReleases(
options?: GitHubPaginationOptions
): Promise<GitHubRelease[]> {
const { client, owner, repo } = await this.api()
const { count = GITHUB_REST_PAGE_DEFAULT, ...rest } = options ?? {}
const ite = client.paginate.iterator(client.rest.repos.listReleases, {
owner,
repo,
...rest,
})
const res = await paginatorToArray(ite, count, (i) => i.data)
return res
}

async listWorkflowRuns(
workflowIdOrFilename: string | number,
options?: {
Expand Down
25 changes: 20 additions & 5 deletions packages/core/src/types/prompt_template.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1029,8 +1029,8 @@ interface WorkspaceFileSystem {

/**
* Copies a file between two paths
* @param source
* @param destination
* @param source
* @param destination
*/
copyFile(source: string, destination: string): Promise<void>

Expand Down Expand Up @@ -2132,9 +2132,7 @@ interface JSONSchemaUtilities {
* Converts a parameters schema to a JSON schema
* @param parameters
*/
fromParameters(
parameters: PromptParametersSchema | undefined
): JSONSchema
fromParameters(parameters: PromptParametersSchema | undefined): JSONSchema
}

interface HTMLTableToJSONOptions {
Expand Down Expand Up @@ -2583,6 +2581,17 @@ interface GitHubUser {
login: string
}

interface GitHubRelease {
id: number
tag_name: string
name: string
draft?: boolean
prerelease?: boolean
html_url: string
published_at: string
body?: string
}

interface GitHub {
/**
* Gets connection information for octokit
Expand Down Expand Up @@ -2733,6 +2742,12 @@ interface GitHub {
*/
listRepositoryLanguages(): Promise<Record<string, number>>

/**
* List latest releases in a GitHub repository
* @param options
*/
listReleases(options?: GitHubPaginationOptions): Promise<GitHubRelease[]>

/**
* Lists tags in a GitHub repository
*/
Expand Down
3 changes: 3 additions & 0 deletions packages/sample/genaisrc/github.genai.mts
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,8 @@ console.log(
const branches = await github.listBranches()
console.log(branches)

const releases = await github.listReleases()
console.log(releases)

if (info.issueNumber)
await github.createIssueComment(info.issueNumber, "Hello from GenAIClient")

0 comments on commit a54497c

Please sign in to comment.