Home
Support Forums

Retrieve Github repo URL inside Netlify plugin

Hey, i’m writing a new Netlify plugin and i was wondering if there is a way to obtain an URL to Github/Gitlab repo of the project that is being deployed. I’ve found the branch name is present in netlifyConfig, but there is not url link to repository
Ideally i would need also access token of the user, but i understand that this probably is not possible since it would be huge security risk :sweat_smile:

Thanks for help

Hey there!

The URL is available in our build environment variables: Build environment variables | Netlify Docs

Access token? Not so sure about that one. Fancy sharing a little bit more about your use case? When there’s a will, there’s a way :slight_smile:

Thanks, i could have thought about the environment variables :sweat_smile:

Sure, my usecase is this: I am working on lowcode solution for developing react apps. We decided for tight integration with Netlify, basic workflow should be:
Deploy your CRA app on Netlify with our custom plugin and you’ll get live editable react-app with vscode in separate iframe. We transpile and bundle the code in the background and refresh your app instantaneously. You are abble to edit your app visualy (clone, remove elements, inline edit labels) or edit the code inside vscode editor right on the deployed webpage.

However, if you edit your app in the browser, you want to access the edited source code, right? In first iteration you are able to download sources as .zip, but we want to integrate with Github/Gitlab API.
This could be done quite easily, but we need access token.
It would be ideal if we could obtain the token from Netlify build environment and therefore user wouldn’t have to go through another round of authentication. With this token user would be able to push the source code right into the repository from which the app was deployed

Is there any way how we could achieve this?

Hi @mecirmartin,

There won’t be a direct way to achieve this. But, you could ask users to create a personal access token: Netlify App and add it as a plugin input: Create Build Plugins | Netlify Docs

I already thought about this solution, but it is not as streamlined and user friendly as it could be if there was way to obtain token from build process.
Anyway, is it enough if user generates Netlify access token and with this token i’m able to authenticate in Github/Gitlab api?

There’s a thin line required to maintain between security and user friendliness. Sometimes, to keep it secure, it’s better to leave it to manual action than automated. Exposing auth token to build environment would give easy access to anyone to be able to hijack into user’s accounts.

No, GitHub/GitLab will need their own access tokens. Netlify’s token won’t give you the ability to access the user’s Git hosts.