Back to Codeberg

feat(issue): read body from file #251

forgejo-contrib-forgejo-cli-pulls-251.md

latest15.4 KB
Original Source

forgejo-contrib/forgejo-cli

Watch20

Star402

Fork

You've already forked forgejo-cli

51

CodeIssues 44Pull requests 8Releases 11Packages 2WikiActivity

feat(issue): read body from file #251

Merged

Cyborusmerged 5 commits from cljoly/issue-body-file into main 2025-12-19 21:18:21 +01:00AGit

Conversation 3Commits 5Files changed 3 +46 -8

cljoly commented 2025-12-19 00:55:13 +01:00

Contributor

Copy link

The current command to create issues accepts the body either on the
command line or by opening a text editor.

I like to write bodies in local Markdown files, so that I can write a
few offline before uploading them. Even if I am online, having the issue
saved on disk gives me more confidence that it won't be lost should
forgejo-cli encounter an error.

This adds the --body-file flag to read the body from a file. This flag
can’t be combined with the --body argument. This is enforced at
runtime by Clap. If both are specified, it will fail with:

text
error: the argument '--body <BODY>' cannot be used with '--body-file <BODY_FILE>'

If the file is missing, the error looks like this:

text
Error: Error reading file `/tmp/f.md`

Caused by:
    No such file or directory (os error 2)

Location:
    src/issues.rs:263:26

The current command to create issues accepts the body either on the command line or by opening a text editor. I like to write bodies in local Markdown files, so that I can write a few offline before uploading them. Even if I am online, having the issue saved on disk gives me more confidence that it won't be lost should forgejo-cli encounter an error. This adds the --body-file flag to read the body from a file. This flag can’t be combined with the --body argument. This is enforced at runtime by Clap. If both are specified, it will fail with: error: the argument '--body \<BODY\>' cannot be used with '--body-file \<BODY_FILE\>' If the file is missing, the error looks like this: Error: Error reading file `/tmp/f.md` Caused by: No such file or directory (os error 2) Location: src/issues.rs:263:26

cljoly force-pushed cljoly/issue-body-file from ca25450c58

Some checks failed

ci/woodpecker/pr/check Pipeline failed

Details

to 913dbebde1

All checks were successful

ci/woodpecker/pr/check Pipeline was successful

Details

2025-12-19 01:02:24 +01:00 Compare

Cyborus requested changes 2025-12-19 02:17:22 +01:00 Dismissed

Cyborus left a comment

Copy link

Thanks! Could you do two more things?

  • Add this for pr create too.
  • Read from stdin when the filename is -.

Thanks! Could you do two more things? - Add this for pr create too. - Read from stdin when the filename is -.

src/issues.rs

Show resolved Hide resolved

| | | | @ -254,0 +259,4 @@ | | | | | | let body_from_file: Option<String> = match body_file { | | | | | | None => None, | | | | | | Some(path) => Some(tokio::fs::read_to_string(&path).await.wrap_err_with(|| { | | | | | | format!("Error reading file{}", path.to_string_lossy()) |

Cyborus commented 2025-12-19 02:14:36 +01:00

Member

Copy link

I think eyre::eyre! would be more fitting here than format!

I think eyre::eyre! would be more fitting here than format!

cljoly commented 2025-12-19 13:07:03 +01:00

Author

Contributor

Copy link

Fair enough, I changed this.

Fair enough, I changed this.

cljoly marked this conversation as resolved

cljoly commented 2025-12-19 12:22:04 +01:00

Author

Contributor

Copy link

@Cyborus wrote in #251 (comment):

Thanks! Could you do two more things?

* Add this for `pr create` too.

* Read from stdin when the filename is `-`.

Sure, I’ll do those things in this MR.

Additionally, I think it would make sense to allow pr/issue comments to be read from a file. I would like to defer that particular bit to a follow-up MR to keep that one small and manageable.

@Cyborus wrote in https://codeberg.org/forgejo-contrib/forgejo-cli/pulls/251#issuecomment-9051804: > Thanks! Could you do two more things? > > * Add this for pr create too. > > * Read from stdin when the filename is -. Sure, I’ll do those things in this MR. Additionally, I think it would make sense to allow pr/issue comments to be read from a file. I would like to defer that particular bit to a follow-up MR to keep that one small and manageable.

👍 1

cljoly added 1 commit 2025-12-19 12:25:56 +01:00

fix: use eyre::eyre! macro for error message building

All checks were successful

ci/woodpecker/pr/check Pipeline was successful

Details

82237b59f6

cljoly added 2 commits 2025-12-19 17:11:00 +01:00

refactor: move read from file to an external function... 2b276e4626

Also add the abilitly to read from stdin

feat: read PR body from file (or stdin)...

Some checks are pending

ci/woodpecker/pr/check Pipeline is pending

Details

cb79bf3534

The mechanism is similar to the one for issues.

Tests:
* an error is returned when the file exists
* submitting an MR with the argument posts the content of that file.

cljoly added 1 commit 2025-12-19 17:14:06 +01:00

fix: cosmetic improvements to comments

All checks were successful

ci/woodpecker/pr/check Pipeline was successful

Details

bd3de3b899

cljoly requested review from Cyborus 2025-12-19 17:15:18 +01:00

cljoly commented 2025-12-19 17:16:12 +01:00

Author

Contributor

Copy link

@Cyborus this is ready for you to take another look please.

@Cyborus this is ready for you to take another look please.

Cyborus approved these changes 2025-12-19 21:18:06 +01:00

Cyborus left a comment

Copy link

Looks great, thanks!

Looks great, thanks!

Cyborus merged commit c56cd3fc8f into main 2025-12-19 21:18:21 +01:00

Cyborus referenced this pull request from a commit 2025-12-19 21:18:23 +01:00 Merge pull request 'feat(issue): read body from file' (#251) from cljoly/issue-body-file into main

cljoly referenced this pull request 2025-12-19 23:20:06 +01:00 feat(pr,issue): submit comments from a file #252

Cyborus referenced this pull request from a commit 2025-12-19 23:25:21 +01:00 feat(pr,issue): submit comments from a file

Cyborus added this to the v0.4.0 milestone 2026-01-07 22:59:09 +01:00

Sign in to join this conversation.

Reviewers

No reviewers

Cyborus

Labels

Clear labels[ Kind/Breaking Breaking change that won't be backward compatible

](#)[ Kind/Bug Something is not working

](#)[ Kind/Design Discussion about UI/UX design

](#)[ Kind/Documentation Documentation changes

](#)[ Kind/Enhancement Improve existing functionality

](#)[ Kind/Feature New functionality

](#)[ Kind/Security This is security issue

](#)[ Kind/Testing Issue or pull request related to testing

](#)[ Kind/Upstream This is an issue with upstream software (Forgejo) that is probably not our fault

](#)

[ Priority

Critical The priority is critical

](#)[ Priority

High The priority is high

](#)[ Priority

Low The priority is low

](#)[ Priority

Medium The priority is medium

](#)

[ Reviewed

Confirmed Issue has been confirmed

](#)[ Reviewed

Duplicate This issue or pull request already exists

](#)[ Reviewed

Invalid Invalid issue

](#)[ Reviewed

Won't Fix This issue won't be fixed

](#)

[ Status

Abandoned Somebody has started to work on this but abandoned work

](#)[ Status

Blocked Something is blocking this issue or pull request

](#)[ Status

Need More Info Feedback is required to reproduce issue or to continue work

](#)

[ Suspicious

](#)

No labels Kind/Breaking Kind/Bug Kind/Design Kind/Documentation Kind/Enhancement Kind/Feature Kind/Security Kind/Testing Kind/Upstream [ Priority

Critical ](/forgejo-contrib/forgejo-cli/pulls?labels=173012) [ Priority

High ](/forgejo-contrib/forgejo-cli/pulls?labels=173013) [ Priority

Low ](/forgejo-contrib/forgejo-cli/pulls?labels=173015) [ Priority

Medium ](/forgejo-contrib/forgejo-cli/pulls?labels=173014) [ Reviewed

Confirmed ](/forgejo-contrib/forgejo-cli/pulls?labels=173007) [ Reviewed

Duplicate ](/forgejo-contrib/forgejo-cli/pulls?labels=173005) [ Reviewed

Invalid ](/forgejo-contrib/forgejo-cli/pulls?labels=173006) [ Reviewed

Won't Fix ](/forgejo-contrib/forgejo-cli/pulls?labels=173008) [ Status

Abandoned ](/forgejo-contrib/forgejo-cli/pulls?labels=173011) [ Status

Blocked ](/forgejo-contrib/forgejo-cli/pulls?labels=173010) [ Status

Need More Info ](/forgejo-contrib/forgejo-cli/pulls?labels=173009) Suspicious

Milestone

Clear milestone

No items

No milestone v0.4.0

Projects

Clear projects

No items

No project

Assignees

Clear assignees

No assignees

2 participants

Notifications Subscribe

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!251

WritePreview

Loading…

Add table

| Rows | | | Columns | |

CancelOK

Add a link

Url Description Hint: With a URL in your clipboard, you can paste directly into the editor to create a link.

CancelOK

CancelSave

Reference in a new issue

Repository

forgejo-contrib/forgejo-cli

Title

Body

Create issue

No description provided.

Delete branch "cljoly/issue-body-file"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?

No Yes