Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GitHub commit email as git author email #7122

Closed
ramank775 opened this issue Dec 8, 2021 · 5 comments
Closed

GitHub commit email as git author email #7122

ramank775 opened this issue Dec 8, 2021 · 5 comments

Comments

@ramank775
Copy link

Is your feature request related to a problem? Please describe

When email privacy is enabled/ commit email is enabled on the github with block command line push with primary email. Currently gitpod configure git user with the primary email which leads to GitHub rejects the commit. User needs to be conscious before starting the work, which i feel adds little manual work for the user, and as a user i am not expecting to do that manually as i am enjoying everything is automated for me already.

Describe the behaviour you'd like

When setting up the gitpod workspace with proper author details. In this case instead of primary email use commit email as author email.

Describe alternatives you've considered

Alternatively if we have user specific variables, so the git author can be configured via init task.

Additional context

Github user email setting

  • GitHub user with email privacy enabled.
  • Block command line pushes that expose my email
@ramank775 ramank775 changed the title GitHub commit email for git user GitHub commit email as git author email Dec 8, 2021
@ramank775
Copy link
Author

Is there any update on this? can someone guide me through the code, i am happy to contribute.

@axonasif
Copy link
Member

axonasif commented Dec 29, 2021

Is there any update on this? can someone guide me through the code, i am happy to contribute.

There are two things that you can do to overwrite some git configuration on Gitpod.

  • By specifying internal git-config variables in your .gitpod.yml

See:

  1. https://www.gitpod.io/docs/references/gitpod-yml#gitconfig
  2. https://git-scm.com/docs/git-config#Documentation/git-config.txt-useremail
    Although it might not be possible to fetch the email from commit history and reference it here dynamically
  • By exporting a git specific variable in your .bashrc dynamically. The variable of your interest is GIT_COMMITTER_EMAIL

Although there are more ways, such as using the ENV keyword on docker or modifying .gitconfig file, but none of these can be set dynamically.

I believe this process will be much more convenient when dotfiles support is there #7337

@ramank775
Copy link
Author

@axonasif that helps.
Closing the issue

@cooperwalter
Copy link

For anyone still encountering this issue, here is my solution. It is based on @axonasif's excellent suggestions.

Here are the full steps automatically configure your private git committer email:

  1. Go to https://github.com/settings/emails and copy your private GitHub email address
  2. Go to https://gitpod.io/user/variables and click "New Variable"
  3. For the name, put GIT_COMMITTER_EMAIL. For the value, put your private Github email address. For the Scope, limit it to a specific repo or use */*to make it available to all your projects.
  4. Add this task to your .gitpod.yml file under the tasks section. This step sets your GIT_COMMITER_EMAIL as your git email address, or it uses your regular GitHub email address if you haven't set GIT_COMMITER_EMAIL.
tasks:
  ...other tasks...
  - name: Configure git committer if needed
    init: |
      git config --global user.email "${GIT_COMMITTER_EMAIL:-$(git config user.email)}"
  1. Commit this change
  2. Re-open your Gitpod workspace
  3. Profit

Hope this helps someone!

@axonasif
Copy link
Member

Thanks for sharing @cooperwalter !

I have one suggestion, you can use before task instead of init as when you will have prebuilds enabled, the modifications made to ~/.gitconfig won't be persisted normally. [1]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants