Forgejo drop-in for actions/github-script: run inline JS with a Forgejo API client, context, and core. No github.com.
- JavaScript 74.2%
- Shell 18.8%
- Makefile 7%
The json-encoded result carries embedded quotes that collapse when spliced into a double-quoted shell comparison via the expression. Switch the e2e to result-encoding: string and pass the value through an env var instead of interpolating it into the script. Action behaviour unchanged. |
||
|---|---|---|
| .forgejo/workflows | ||
| src | ||
| tests | ||
| .gitignore | ||
| action.yml | ||
| CHANGELOG.md | ||
| LICENSE | ||
| Makefile | ||
| MIGRATION.md | ||
| README.md | ||
Forgejo Script
Forgejo's actions/github-script. Run an inline JavaScript script with a
Forgejo API client, the workflow context, and core, no github.com, no
octokit. The client speaks the Forgejo API.
Part of the Fjord Actions bundle.
Usage
permissions:
contents: read
# plus whatever your script needs (issues: write, pull-requests: write, ...)
jobs:
triage:
runs-on: [self-hosted, Linux]
steps:
- uses: https://rasterhub.com/rasterstate/forgejo-script@v1
with:
script: |
const { owner, repo } = context.repo;
const pr = context.payload.pull_request;
if (pr && pr.title.startsWith('WIP')) {
await api.post(`/repos/${owner}/${repo}/issues/${pr.number}/labels`, {
labels: ['work-in-progress'],
});
core.info('labelled WIP');
}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # a Forgejo token on Forgejo
The script runs as the body of an async function, so top-level await works and
return <value> populates the result output.
In scope
| Name | What |
|---|---|
api |
Forgejo API client (see below). The token is preset. |
context |
repo (owner/repo), eventName, sha, ref, payload (the event JSON), issue, runId, actor, serverUrl, apiUrl, ... |
core |
Logging, setOutput, setFailed, setSecret, input helpers. |
fetch |
The global fetch, for anything the client doesn't cover. |
require, process, console |
The usual Node globals. |
The api client
Paths are relative to the API base (/repos/owner/name/...). Helpers return the
parsed JSON body and throw on a non-2xx status:
const issues = await api.get(`/repos/${owner}/${repo}/issues?state=open`);
await api.post(`/repos/${owner}/${repo}/issues/${n}/comments`, { body: 'hi' });
await api.patch(`/repos/${owner}/${repo}/issues/${n}`, { state: 'closed' });
await api.del(`/repos/${owner}/${repo}/issues/comments/${id}`);
const all = await api.paginate(`/repos/${owner}/${repo}/issues`); // follows Link
const res = await api.request('GET', '/version'); // {status, ok, data}
Inputs
| Input | Default | Description |
|---|---|---|
script |
(required) | The JavaScript to run. |
result-encoding |
json |
Encode the return value for the result output: json or string. |
token |
GITHUB_TOKEN / FORGEJO_TOKEN env |
Forgejo token for the client. |
api_url |
GITHUB_API_URL, then GITHUB_SERVER_URL+/api/v1 |
Forgejo API base. |
Outputs
| Output | Description |
|---|---|
result |
The script return value, encoded per result-encoding. |
See MIGRATION.md for differences from actions/github-script.
License
MIT, see LICENSE.