forked from heavy-duty/stoke
feat: add repo collaborator command
This commit is contained in:
parent
c981a1258d
commit
25670253ea
3 changed files with 51 additions and 0 deletions
21
README.md
21
README.md
|
|
@ -309,6 +309,27 @@ forgejo branch list -o kimi-reviewer-andresmgsl -r box
|
||||||
|
|
||||||
Calls `GET /api/v1/repos/{owner}/{repo}/branches` and auto-paginates.
|
Calls `GET /api/v1/repos/{owner}/{repo}/branches` and auto-paginates.
|
||||||
|
|
||||||
|
### `forgejo collaborator add`
|
||||||
|
|
||||||
|
Add a collaborator to a repository.
|
||||||
|
|
||||||
|
```text
|
||||||
|
Options:
|
||||||
|
-o, --owner <owner> repository owner (required)
|
||||||
|
-r, --repo <repo> repository name (required)
|
||||||
|
-u, --user <username> username of the collaborator (required)
|
||||||
|
--permission <permission> read, write, or admin (default: write)
|
||||||
|
```
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
forgejo collaborator add -o kimi-reviewer-andresmgsl -r infra -u andres --permission admin
|
||||||
|
forgejo collaborator add -o kimi-reviewer-andresmgsl -r infra -u dan --permission admin
|
||||||
|
```
|
||||||
|
|
||||||
|
Calls `PUT /api/v1/repos/{owner}/{repo}/collaborators/{user}`.
|
||||||
|
|
||||||
## Architecture
|
## Architecture
|
||||||
|
|
||||||
```text
|
```text
|
||||||
|
|
|
||||||
|
|
@ -143,6 +143,12 @@ class ForgejoClient {
|
||||||
async listBranches(owner, repo, opts = {}) {
|
async listBranches(owner, repo, opts = {}) {
|
||||||
return this.getAll(`/repos/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/branches`, opts);
|
return this.getAll(`/repos/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/branches`, opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async addCollaborator(owner, repo, username, permission) {
|
||||||
|
return this.request('PUT', `/repos/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/collaborators/${encodeURIComponent(username)}`, {
|
||||||
|
permission,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { ForgejoClient };
|
module.exports = { ForgejoClient };
|
||||||
|
|
|
||||||
24
src/cli.js
24
src/cli.js
|
|
@ -529,6 +529,30 @@ branchCmd
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const collaborator = program
|
||||||
|
.command('collaborator')
|
||||||
|
.description('Manage repository collaborators');
|
||||||
|
|
||||||
|
collaborator
|
||||||
|
.command('add')
|
||||||
|
.description('Add a collaborator to a repository')
|
||||||
|
.requiredOption('-o, --owner <owner>', 'repository owner')
|
||||||
|
.requiredOption('-r, --repo <repo>', 'repository name')
|
||||||
|
.requiredOption('-u, --user <username>', 'username of the collaborator')
|
||||||
|
.option('--permission <permission>', 'permission level: read, write, admin', 'write')
|
||||||
|
.action(async (options) => {
|
||||||
|
try {
|
||||||
|
const config = loadConfig();
|
||||||
|
const client = ForgejoClient.fromConfig(config);
|
||||||
|
await client.addCollaborator(options.owner, options.repo, options.user, options.permission);
|
||||||
|
console.log(`Added ${options.user} as ${options.permission} collaborator to ${options.owner}/${options.repo}.`);
|
||||||
|
} catch (err) {
|
||||||
|
console.error(`Failed to add collaborator: ${err.message}`);
|
||||||
|
if (err.status) console.error(`HTTP status: ${err.status}`);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
program.parseAsync(process.argv).catch((err) => {
|
program.parseAsync(process.argv).catch((err) => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue