Skip to content
Gerrit Uitslag edited this page Jun 4, 2023 · 7 revisions

The translation tool uses an installed git binary to interact with remote git repositories. Single git commands are wrapped in the GitService and the GitRepository.

Also it uses some libraries to interact with the websites of GitHub, GitLab and Bitbucket via their API.

API for forking and initiating pull/merge requests

For each service a token can be registered for translation tool's user account, which allows to use the GitHub API as that user by the translation tool. The forks are stored in this user account. Pull/merge requests will be made from this account.

Tokens for access the service's user account

  • GitHub: At https://github.com/settings/tokens you can make an classic token in the section Personal access tokens > Tokens(classic). The permission repo is enough. TODO: probably it is better to move to a newer type of token, but I have to fiddle out which one meets our purposes the best. Suggestions welcome.
  • GitLab: At https://gitlab.com/-/profile/personal_access_tokens you can make a token with the scope api.
  • Bitbucket:

SSH access for pushing code

Pull requests are performed authenticated by a ssh key, while using the git commands. So not directly via the API.

Separated user account for testing, next to your normal GitHub account

For development purpose it is may helpful to setup a second git account. This blogpost (see copy below) describes how to setup multiple ssh keys for multiple GitHub accounts.

Register the public key for your key

Example multiple account setup

For the test user you create an own ssh key, and add the public key to the GitHub user account of your test user. For more details about setting up ssh: https://help.github.com/en/articles/connecting-to-github-with-ssh

Next, create on your machine a config for ssh in the file: ~/.ssh/config with two blocks per service:

Host github.com
  HostName github.com
  User git
  PreferredAuthentications publickey
  IdentityFile ~/.ssh/fileofyourmainkey

Host translationtool.github.com
  HostName github.com
  User git
  PreferredAuthentications publickey
  IdentityFile ~/.ssh/fileofyourtestaccountkey

Host gitlab.com
  HostName gitlab.com
  User git
  PreferredAuthentications publickey
  IdentityFile ~/.ssh/fileofyourmainkey

Host translationtool.gitlab.com
  HostName gitlab.com
  User git
  PreferredAuthentications publickey
  IdentityFile ~/.ssh/fileofyourtestaccountkey

Host bitbucket.org
  HostName bitbucket.org
  User git
  PreferredAuthentications publickey
  IdentityFile ~/.ssh/fileofyourmainkey

Host translationtool.bitbucket.org
  HostName bitbucket.org
  User git
  PreferredAuthentications publickey
  IdentityFile ~/.ssh/fileofyourtestaccountkey

You can test the connection with:

This should return a short message with the name of your test user. If not, the configuration is not complete. Respectively:

Hi translation-tester! You've successfully authenticated, but GitHub does not provide shell access.
Welcome to GitLab, @dokuwiki-translation-tester!
authenticated via ssh key.

You can use git to connect to Bitbucket. Shell access is disabled

For more details, a verbose connection test:



Backup copy from http://sampreshan.svashishtha.com/2012/05/20/quicktip-github-multiple-accounts-access-with-ssh/

QuickTip : Github Multiple Accounts Access with ssh

ShriKant Vashishtha · May 20, 2012 · Leave a Comment

Let’s say we have two github accounts named “shrikant-home” and “shrikant-work”.

I would like to access both accounts from ssh.

I hope you have already created public and private keys for both github accounts and added in the ssh settings as mentioned at http://help.github.com/mac-set-up-git/

Now create a file named ~/.ssh/config file and make following entries

[bash]
Host shrikant-home.github.com
HostName github.com
User shrikant-home
PreferredAuthentications publickey
IdentityFile ~/.ssh/shrikant-home

Host shrikant-work.github.com
HostName github.com
User shrikant-work
PreferredAuthentications publickey
IdentityFile ~/.ssh/shrikant-work
[/bash]

In above entries we made two different aliases “shrikant-home.github.com” and “shrikant-work.github.com” for same HostName github.com. This change is very important for rest of the remaining changes.

Now add the private keys “shrikant-home” and “shrikant-work” with ssh-add command as follows [bash] $ cd ~/.ssh $ ssh-add ./shrikant-home $ ssh-add ./shrikant-work [/bash]

The listing of ~/.ssh directory is as follows for clarity:

[bash]
$ ls
config shrikant-home
shrikant-home.pub shrikant-work
shrikant-work.pub known-host
[/bash]

Let’s say we have “project-home” repository for “shrikant-home” github account and “project-work” repository for “shrikant-work” github account. You need to do the “git remote add” to alias host names with related github account id as follows:

[bash]
$ git remote add <github account id> git@<related github host alias>:<github account>/projectname.git
[/bash]

Here’s an example for “project-home” repository

[bash]
$ cd project-home
$ git remote add shrikant-home [email protected]:shrikant-home/project-home.git
[/bash]

In order to do any commit in this project, you’ll have to use following “git push” command after “git add” and “git commit”

[bash]
git push <user-name> master
[/bash]

So in above case it will be:

[bash]
$ git push shrikant-home master
[/bash]

So to reiterate and for the sake of clarity if you want to push changes to “project-work” repository, you need to do “git remote add” with “shrikant-work” userid with related host alias “shrikant-work.github.com” followed by “git push shrikant-work master”

Read more!

Process

Files

Maintenance/development

Documentation

Clone this wiki locally