feat: add label management for repositories and issues #280 #311

Closed
woodworker wants to merge 2 commits from woodworker:feature/issue-labels into main
First-time contributor

Implements issue #280 - adds label commands that were missing for
repositories and issues while already existing for orgs and PRs.

New commands:

  • fj repo label list/add/edit/rm - manage repository labels
  • fj issue view labels - view labels on an issue
  • fj issue edit labels --add/--rm - add/remove labels from issues

Also shows labels in default issue view when present.

Refactors label rendering utilities (render_label, render_label_list)
from prs.rs to main.rs for shared use across modules.

This is coded via claude code with opus 4.5
i checked the code as far as possible for me, i know a bit of rust, no senior in rust yet
tested to create/delete repo labels, and adding removing labels to an issue

i told claude to refactor the label rendering to be moved to main.rs as it was in prs.rs since this was the only place that rendered issues yet
i put it into main because main.rs already had a few rendering function and i did not want to make the pr even bigger and extract the rendering stuff into thier own file
also told claude to stay stylewise as close a s possible to the existing code

if you dont want to integrate it because of ai i totally understand but i wanted that feature and had a claude subscription

The Initial Plan Documet:

Issue Labels Feature Design

Issue: #280
Date: 2026-01-28

Summary

Add label management for repositories and issues, addressing the feature gap where labels exist for orgs and PRs but not for issues or repos.

New Commands

Repository Labels

fj repo label list                              # List all repository labels
fj repo label add <name> --color <hex> [--description <text>] [--exclusive]
fj repo label edit <name> [--name <new>] [--color <hex>] [--description <text>] [--exclusive] [--archived]
fj repo label rm <name>

Issue Labels

fj issue view labels <issue>                    # View labels on an issue
fj issue edit labels <issue> --add <name>... --rm <name>...

Code Changes

Move to src/main.rs

Extract shared label rendering utilities from prs.rs:

  • render_label_list() - renders a list of labels
  • render_label() - renders a single label with colors
  • parse_color() - parses hex color string
  • luma() - calculates luminance for text contrast
  • darken() - darkens color for exclusive label categories

Modify src/repo.rs

  • Add Label variant to RepoCommand enum with nested LabelSubcommand
  • Add handler functions: list_repo_labels(), add_repo_label(), edit_repo_label(), remove_repo_label()

Modify src/issues.rs

  • Add Labels to ViewCommand enum
  • Add Labels to EditCommand enum
  • Add handlers: view_issue_labels(), edit_issue_labels()

Modify src/prs.rs

  • Remove moved functions
  • Import from crate:: instead

Modify src/org.rs

  • Update imports to use crate::render_label_list

API Mapping

Repository Labels

Command API Method
repo label list api.issue_list_labels(owner, repo, query)
repo label add api.issue_create_label(owner, repo, CreateLabelOption)
repo label edit api.issue_edit_label(owner, repo, id, EditLabelOption)
repo label rm api.issue_delete_label(owner, repo, id)

Issue Labels

Command API Method
issue view labels api.issue_get_issue(...) then read .labels
issue edit labels --add api.issue_add_label(owner, repo, index, IssueLabelsOption)
issue edit labels --rm api.issue_remove_label(owner, repo, index, id)

Error Handling

  • Unknown label names: Warn but continue (matches PR behavior)
  • Empty --add/--rm lists: No-op, no error
  • Color input: Accept with or without # prefix, error on invalid hex
  • Empty label lists: Print nothing (consistent with PR behavior)
  • Permission errors: Bubble up with context

Reused Utilities

  • prs::render_label_list() → moved to main.rs
  • prs::render_label() → moved to main.rs
  • issues::label_names_to_ids() - converts label names to IDs
Implements issue #280 - adds label commands that were missing for repositories and issues while already existing for orgs and PRs. New commands: - fj repo label list/add/edit/rm - manage repository labels - fj issue view labels - view labels on an issue - fj issue edit labels --add/--rm - add/remove labels from issues Also shows labels in default issue view when present. Refactors label rendering utilities (render_label, render_label_list) from prs.rs to main.rs for shared use across modules. **This is coded via claude code with opus 4.5** i checked the code as far as possible for me, i know a bit of rust, no senior in rust yet tested to create/delete repo labels, and adding removing labels to an issue i told claude to refactor the label rendering to be moved to main.rs as it was in prs.rs since this was the only place that rendered issues yet i put it into main because main.rs already had a few rendering function and i did not want to make the pr even bigger and extract the rendering stuff into thier own file also told claude to stay stylewise as close a s possible to the existing code if you dont want to integrate it because of ai i totally understand but i wanted that feature and had a claude subscription The Initial Plan Documet: # Issue Labels Feature Design **Issue:** https://codeberg.org/forgejo-contrib/forgejo-cli/issues/280 **Date:** 2026-01-28 ## Summary Add label management for repositories and issues, addressing the feature gap where labels exist for orgs and PRs but not for issues or repos. ## New Commands ### Repository Labels ``` fj repo label list # List all repository labels fj repo label add <name> --color <hex> [--description <text>] [--exclusive] fj repo label edit <name> [--name <new>] [--color <hex>] [--description <text>] [--exclusive] [--archived] fj repo label rm <name> ``` ### Issue Labels ``` fj issue view labels <issue> # View labels on an issue fj issue edit labels <issue> --add <name>... --rm <name>... ``` ## Code Changes ### Move to `src/main.rs` Extract shared label rendering utilities from `prs.rs`: - `render_label_list()` - renders a list of labels - `render_label()` - renders a single label with colors - `parse_color()` - parses hex color string - `luma()` - calculates luminance for text contrast - `darken()` - darkens color for exclusive label categories ### Modify `src/repo.rs` - Add `Label` variant to `RepoCommand` enum with nested `LabelSubcommand` - Add handler functions: `list_repo_labels()`, `add_repo_label()`, `edit_repo_label()`, `remove_repo_label()` ### Modify `src/issues.rs` - Add `Labels` to `ViewCommand` enum - Add `Labels` to `EditCommand` enum - Add handlers: `view_issue_labels()`, `edit_issue_labels()` ### Modify `src/prs.rs` - Remove moved functions - Import from `crate::` instead ### Modify `src/org.rs` - Update imports to use `crate::render_label_list` ## API Mapping ### Repository Labels | Command | API Method | |---------|------------| | `repo label list` | `api.issue_list_labels(owner, repo, query)` | | `repo label add` | `api.issue_create_label(owner, repo, CreateLabelOption)` | | `repo label edit` | `api.issue_edit_label(owner, repo, id, EditLabelOption)` | | `repo label rm` | `api.issue_delete_label(owner, repo, id)` | ### Issue Labels | Command | API Method | |---------|------------| | `issue view labels` | `api.issue_get_issue(...)` then read `.labels` | | `issue edit labels --add` | `api.issue_add_label(owner, repo, index, IssueLabelsOption)` | | `issue edit labels --rm` | `api.issue_remove_label(owner, repo, index, id)` | ## Error Handling - **Unknown label names:** Warn but continue (matches PR behavior) - **Empty --add/--rm lists:** No-op, no error - **Color input:** Accept with or without `#` prefix, error on invalid hex - **Empty label lists:** Print nothing (consistent with PR behavior) - **Permission errors:** Bubble up with context ## Reused Utilities - `prs::render_label_list()` → moved to `main.rs` - `prs::render_label()` → moved to `main.rs` - `issues::label_names_to_ids()` - converts label names to IDs
feat: add label management for repositories and issues
Some checks failed
ci/woodpecker/pr/check Pipeline failed
084eb66df8
Implements issue #280 - adds label commands that were missing for
repositories and issues while already existing for orgs and PRs.

New commands:
- fj repo label list/add/edit/rm - manage repository labels
- fj issue view labels - view labels on an issue
- fj issue edit labels --add/--rm - add/remove labels from issues

Also shows labels in default issue view when present.

Refactors label rendering utilities (render_label, render_label_list)
from prs.rs to main.rs for shared use across modules.
style: apply cargo fmt
All checks were successful
ci/woodpecker/pr/check Pipeline was successful
853716c368
Member

This is coded via claude code with opus 4.5
[...]
if you dont want to integrate it because of ai i totally understand but i wanted that feature and had a claude subscription

Yes, while I appreciate your desire to contribute, I cannot accept this PR because of my conscience about the cultural and environmental effects of AI, and my concerns about the copyright of the output. Thank you for your understanding.

> **This is coded via claude code with opus 4.5** > [...] > if you dont want to integrate it because of ai i totally understand but i wanted that feature and had a claude subscription Yes, while I appreciate your desire to contribute, I cannot accept this PR because of my conscience about the cultural and environmental effects of AI, and my concerns about the copyright of the output. Thank you for your understanding.
Cyborus closed this pull request 2026-01-28 17:32:02 +01:00
woodworker deleted branch feature/issue-labels 2026-01-28 17:35:24 +01:00
Author
First-time contributor

Maybe add this Information to the README so no further attempts of AI pr are made

Maybe add this Information to the README so no further attempts of AI pr are made
Member

Yes that's a good idea, I've meant to for a little while now.

Yes that's a good idea, I've meant to for a little while now.
All checks were successful
ci/woodpecker/pr/check Pipeline was successful
Required
Details

Pull request closed

Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
forgejo-contrib/forgejo-cli!311
No description provided.