Skip to content

Conversation

@pepicrft
Copy link
Contributor

@pepicrft pepicrft commented Mar 8, 2025

I'm user of Codeberg, a hosted instance of the Git forge Forgejo, and I'd like to use UBI against repositories in those repos.

Since Forgejo mimics the API of GitHub, the implementation of Forgejo's forge symbol is very much a copy & paste of GitHub's. Please, let me know if you'd want me to extract some common functionality into another module for the purpose of reusability.

@autarch
Copy link
Member

autarch commented Mar 15, 2025

Hi, thanks for your PR! I'm pretty finicky about my projects (see this blog post for details), so I rarely merge a PR as-is. I can move forward on your PR in one of two ways:

  1. I check it out locally, fiddle with it as needed, merge it locally, and simply close this PR. This will preserve at least one commit with your name on it, but the PR will show up as closed in your GitHub stats.
  2. If you enable me to push directly to your PR branch (which is the default when you make a PR), I can do my fiddling, then force push to your PR branch and merge the resulting PR. Again, this will preserve at least one commit with your name on it, but you also get credit for the PR merge in your GitHub stats. The only downside is that I will be force pushing directly to your PR branch. Note that this will not work if the PR branch is named master. GitHub doesn't allow me to push to the default branch of your fork.

Please let me know which approach you'd prefer. If I don't hear from you before I get around to working on this PR I'll go with option 1.

Thanks again for your contribution!

@autarch
Copy link
Member

autarch commented Mar 16, 2025

I spent some time trying to tweak this, but I finally realized that Forgejo does not actually have the same API as GitHub, at least not the same as the GH v4 REST API.

Specifically, when you get releases from GitHub, you get something like this:

{
  "assets": [
    {
      "url": "https://api.github.com/repos/houseabsolute/precious/releases/assets/237809592",
      "name": "precious-FreeBSD-x86_64.tar.gz",
  ],
}

But Forgejo doesn't include a url field for assets. You can construct the URL from the asset's id, but even using that constructed URL, it doesn't seem like you can download the actual asset contents that way, unlike GitHub.

@autarch
Copy link
Member

autarch commented Mar 16, 2025

All of which is to say, this does need its own forge type. But don't work on that now. In working on this myself, I've done a bunch of refactoring that I'd like to finish up first.

@pepicrft
Copy link
Contributor Author

Hi @autarch 👋🏼

First of all, thanks for your transparency. I'm open to whatever method works best for you (I'm not that attached to the idea of having to preserve my name in the work).

But Forgejo doesn't include a url field for assets. You can construct the URL from the asset's id, but even using that constructed URL, it doesn't seem like you can download the actual asset contents that way, unlike GitHub.

This is something I missed completely. Is there anything I can do to help you understand this better?

Thanks a lot for helping move this one forward. I started moving some of my repositories to Codeberg, and being able to use UBI through Mise to install tools would be very valuable.

@autarch
Copy link
Member

autarch commented Apr 12, 2025

So I think I'm done with the refactoring I was planning on doing. If you want to take a stab at adding support for ForgeJo, that'd be great!

@pepicrft
Copy link
Contributor Author

@autarch I doubt I'll find time in the following weeks to complete this work. Feel free to close it and I'll open a new one if I find the time for it.

@autarch
Copy link
Member

autarch commented Apr 25, 2025

That's fine. I may take a look at some point, but right now I'm mostly filling my free time up by playing Satisfactory ;)

@pepicrft
Copy link
Contributor Author

@autarch I found some time to work on it. I'd appreciate if you could review the work and let me know how to proceed :)

Copy link
Member

@autarch autarch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good. Thanks! There's a few things missing:

  • Let's add CODEBERG_TOKEN as an env var to check for a token.
  • The builder.rs code docs should mention the token env vars.
  • The ForgeType::from_url code needs to accounts for the codeberg domain.
  • It'd be great to add an integration test in ubi-cli/tests/ubi.rs. After fixing the above issue, I was able to get https://codeberg.org/Cyborus/forgejo-cli/releases installed using ubi, so I think this is a good one to use for the integration test. Note that it doesn't have a macOS release, so the test code needs to be configured to not run on macOS. You can see a bunch of examples of per-OS conditions in that file already.

Thanks again!

Comment on lines 137 to 138
env::remove_var("GITLAB_TOKEN");
env::remove_var("CI_JOB_TOKEN");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be whatever env var is used for a forgejo token. I think it'd make sense to support both CODEBERG_TOKEN and FORGEJO_TOKEN.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd vote for FORGEJO_TOKEN, following my other comments

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll use FORGEJO_TOKEN. Let me know if you'd want CODEBERG_TOKEN to be added too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should add both. It doesn't hurt.

ubi/src/forge.rs Outdated

const GITHUB_DOMAIN: &str = "github.com";
const GITLAB_DOMAIN: &str = "gitlab.com";
const FORGEJO_DOMAIN: &str = "codegerg.org";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has a typo in the domain name. Also, I think we should just call it CODEBERG_DOMAIN for simplicity.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, the software is forgejo, the default instance chosen here codeberg.org, so (apart from the typo) I think thats okay?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer the variable name to match the actual domain name, just for consistency.

Copy link

@Finkregh Finkregh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the effort!

ubi/src/forge.rs Outdated

const GITHUB_DOMAIN: &str = "github.com";
const GITLAB_DOMAIN: &str = "gitlab.com";
const FORGEJO_DOMAIN: &str = "codegerg.org";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, the software is forgejo, the default instance chosen here codeberg.org, so (apart from the typo) I think thats okay?

ubi/src/forge.rs Outdated

const GITHUB_API_BASE: &str = "https://api.github.com";
const GITLAB_API_BASE: &str = "https://gitlab.com/api/v4";
const CODEBERG_API_BASE: &str = "https://codeberg.org/api/v1";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That should be FORGEJO_API_BASE, following the above variable?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I want this the other way around, so it matches the domain name.

ubi/src/forge.rs Outdated
ForgeType::GitLab => Url::parse(GITLAB_API_BASE).unwrap(),
// The maintainers of Forgejo is Codeberg, hence why the URL
// doesn't align with the name of the Git forge.
ForgeType::Forgejo => Url::parse(CODEBERG_API_BASE).unwrap(),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the api base changes depending on which forgejo instance you want to talk to?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can provide your own --api-base-url via the CLI or API, so this is just the default.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which is to say that this is correct as is.

Comment on lines 137 to 138
env::remove_var("GITLAB_TOKEN");
env::remove_var("CI_JOB_TOKEN");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd vote for FORGEJO_TOKEN, following my other comments

@pepicrft
Copy link
Contributor Author

@Finkregh & @autarch thanks a lot for your review 🙏🏼 and apologies for the delay here. I addressed your comments and pushed the changes. Could you give it another look?

@autarch
Copy link
Member

autarch commented Aug 23, 2025

I realized when looking at this that the only difference between this and GitHub is the one field name in the assert data structure. And we could reuse the existing Asset struct by just adding #[serde(alias = "browser_download_url")] to the struct field.

So given that, I think I want to refactor things a bit more to reduce code duplication. I think it's probably easiest for me to just take what you have and do the rest myself. Are you okay with that?

@pepicrft
Copy link
Contributor Author

So given that, I think I want to refactor things a bit more to reduce code duplication. I think it's probably easiest for me to just take what you have and do the rest myself. Are you okay with that?

Totally :). I can't think of a better person to drive the refactors needed for that.

I realized that there was almost no difference in the forge code, even with Forgejo to come, so
there's no need for the `dyn` stuff.
@autarch autarch force-pushed the codeberg branch 3 times, most recently from 47a3ae5 to 244bfd1 Compare September 14, 2025 15:17
@autarch autarch force-pushed the codeberg branch 2 times, most recently from e767346 to 0faa9a6 Compare September 14, 2025 16:10
@autarch autarch merged commit 94b6322 into houseabsolute:master Sep 14, 2025
31 checks passed
@autarch
Copy link
Member

autarch commented Sep 14, 2025

This is in v0.8.0, which I just released. Thanks again!

jdx pushed a commit to jdx/mise that referenced this pull request Oct 11, 2025
Forgejo support is added in
houseabsolute/ubi#107, but I don't know what to
do so ignored it.
jdx pushed a commit to jdx/mise that referenced this pull request Nov 30, 2025
This reverts commit 28eb48e. (#6700)

Forgejo support is added in
houseabsolute/ubi#107, but this PR just ignores
it.

The regression #6699 was caused
by
houseabsolute/ubi@a7742e6,
which wrapped errors with contexts.
To work around this, we need to keep `anyhow::Error` as is, instead of
converting to `eyre::Error`, until we check the status code.

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants