AdaGPT (2 Part Series)
1
AdaGPT: AI support for Issues and Pull Requests right at your fingertips!
2
AdaGPT: My Learnings While Building a GitHub Action
I posted my GitHub Action, AdaGPT, for the GitHub Hackathon here on DEV.to a few days ago. While implementing this action, I learned a lot and want to take the time to share them. Here are my learnings in no particular order:
Action Templates
To get started quickly with a JavaScript action, I recommend using the official templates from GitHub for JavaScript and TypeScript.
TypeScript Types
Life is easier with static types, at least for me. If you use TypeScript, GitHub provides the @octokit/webhooks-types package with official type definitions for all of GitHub's webhooks event types and payloads.
}
});
The REST API client for JavaScript has extensive documentation with many code examples.
GitHub Context
The package @actions/github provides a hydrated Context from the current workflow environment with lots of useful information.
The current repository and issue number can be retrieved directly from context instead of providing them via an input or reading them from an environment variable:
import * as core from '@actions/core'
import * asfrom '@actions/'
//---------------------------------------------------------
Run Action Locally
You can use the act package to run your workflow and action locally so you don't have to commit and push every time you want to test the changes. It works really well and helps you develop much faster.
If you run the workflow locally, you will not get an automatic GitHub Token for interacting with the REST API. This means you need to create a Personal Access Token and provide this token as GITHUB_TOKEN for workflow execution. I would recommend creating a local .env file with your PAT:
file: .env
GITHUB_TOKEN=
This secret file can be passed to act when running locally:
act issue_comment --secret-file .env
As usual, the token is available within the workflow via the syntax ${ secrets.}}.
Pagination
The REST API is paginated and returns up to 100 items per page. You can use Pagination API to read all items of a particular endpoint:
import * as core from '@actions/core'
import * as githb from '@actions/'
import type { Issue } from '@/webhooks-types';
});
Write Job Summary
The Job Summary is a markdown file with the results of the jobs within a workflow. This blog post from GitHub gives a good overview.
For example, I'm writing this job summary for my GitHub Action:
import * as core from '@actions/core'
import * as github from '@actions/github'
a
.write();
The rendered markdown looks like this:
Job Summary
Job Summary
I hope you found this post helpful. If you have any questions or comments, feel free to leave them below. If you'd like to connect with me, you can find me on LinkedIn or GitHub. Thanks for reading!
Top comments (0)