octokit / app.js

GitHub Apps toolset for Node.js
MIT License
158 stars 34 forks source link

[FEAT]: method for generating installation url #541

Closed rpmccarter closed 5 months ago

rpmccarter commented 6 months ago

Describe the need

We have multiple github apps - one for each environment of our service. We have an endpoint that simply returns the installation url for the github app. Right now, the endpoint looks something like this:

    const baseUrl = process.env.NODE_ENV === 'development'
      ? 'https://github.com/apps/mintlify-development/installations/new'
      : 'https://github.com/apps/mintlify/installations/new';

    const url = new URL(baseUrl);

    url.searchParams.append('state', stateString);

    return url.toString();

I wish we didn't have to hard-code the github app name or store it as an env var. I noticed that the @octokit/oauth-app package has a convenient method app.getWebFlowAuthorizationUrl(options) which generates the authorization URL. I looked for a similar function within the octokit app but wasn't able to find anything. Would be a neat little feature to have - happy to implement as well!

SDK Version

No response

API Version

No response

Relevant log output

No response

Code of Conduct

github-actions[bot] commented 6 months ago

👋 Hi! Thank you for this contribution! Just to let you know, our GitHub SDK team does a round of issue and PR reviews twice a week, every Monday and Friday! We have a process in place for prioritizing and responding to your input. Because you are a part of this community please feel free to comment, add to, or pick up any issues/PRs that are labled with Status: Up for grabs. You & others like you are the reason all of this works! So thank you & happy coding! 🚀

gr2m commented 6 months ago

what I usually do is to retrieve the app's HTML URL

const { data: appInfo } = await app.octokit.request("GET /app")
const installUrl = `${appInfo.html_url}/installations/new`

Does that work for you?

rpmccarter commented 6 months ago

I could definitely use that instead, and the implementation of this method would probably look just like that, I just like the convenience of app.getWebFlowAuthorizationUrl(options) and wanted to check if it was something that could be added to the GitHub app - it's nice to be able to create the exact installation link without having to refer to the github api docs. If this is too trivial that's fine :)

gr2m commented 6 months ago

The OAuth URL method is coming from this package: https://github.com/octokit/oauth-methods.js. We don't have a counterpart with methods for apps, but worth thinking about.

I suggest we leave this issue open, maybe others can share their perspective and we can pick it up again in future

rpmccarter commented 5 months ago

Created PR #542 to address this, mostly for fun - let me know what you think! No worries if it doesn't get merged

github-actions[bot] commented 5 months ago

:tada: This issue has been resolved in version 15.1.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: