It's all about the answers!

Ask a question

Is there a way to automatically register Git repositories?


Michael Ricketts (3314) | asked Mar 08 '16, 6:50 a.m.
We have a large number (around 50) of git repositories that we wish to link to work items on RTC.
We can go through and do this one at a time, but it is extremely tedious and error prone to add them all this way.  Also, we frequently add new Git repositories that we want to register.

Is there any way to register a Git repository programatically (via the REST or OSLC api maybe?

We're using RTC 5.0.2 if that makes a difference

Thanks

Comments
Liora Milbaum commented Aug 15 '16, 2:04 a.m.

 Did you find a solution for your problem? I am facing the same challenge.

2 answers



permanent link
Michael Ricketts (3314) | answered Aug 15 '16, 5:04 a.m.
Sort of...
The following works for me on 5.0.2 - I have not tested on v6.x.  It will set $key to the git repository key.


#!/bin/sh
jazzRepoUrl="https://localhost:9443/ccm"
projecID=_.....     # UUID of the jazz project area
jazzUserId=ADMIN
jazzPassword=admin
jazzCookiesFile=/tmp/jazzCookies.txt
name=GitRepo
description="A Git Repository"

ownerItemId=$projectId
currentPAItemId=$projectId


# authenticate
curl -v -k -c $jazzCookiesFile "$jazzRepoUrl/authenticated/identity" >&2
curl -v -k -L -b $jazzCookiesFile -c $jazzCookiesFile -d j_username=$jazzUserId -d j_password=$jazzPassword "$jazzRepoUrl/authenticated/j_security_check" >&2

# register...
curl -v -w "\nRESULT=%{http_code}\n" -k -b $jazzCookiesFile -H "Accept:text/json" -X POST "$jazzRepoUrl/service/com.ibm.team.git.common.internal.IGitRepositoryRegistrationRestService/RegisterGitRepository?name=$name&ownerItemId=$ownerItemId&currentPAItemId=$currentPAItemId&url=$url&description=$description" >/tmp/registerOut
key=$(sed -n 's/^.*"key":"\([a-z0-9]*\)".*$/\1/p' /tmp/registerOut)
if [ "$key" = "" ] ; then
    echo "FAILED"
    cat >&2 /tmp/registerOut
    rm -f $jazzCookiesFile /tmp/registerOut
    exit 1
fi
rm -f /tmp/registerOut

# set commit uri format
curl -v -w "\nRESULT=%{http_code}\n" -k -b $jazzCookiesFile -H "Accept:text/json" -X POST "$jazzRepoUrl/service/com.ibm.team.git.common.internal.IGitRepositoryRegistrationRestService/updateRegisteredGitRepository?repoKey=$key&name=$name&description=$description&url=$url&ownerItemId=$projectId&configurationData=%7B%22com_ibm_team_git_config_use_repository_process_area_unmapped_refs%22%3A%22true%22%2C%22com_ibm_team_git_config_commit_url_format%22%3A%22%24repo%2Fcommit%2F%24sha1%22%2C%22com_ibm_team_git_config_git_server_credentials%22%3A%7B%22userId%22%3A%22%22%2C%22encryptedPassword%22%3A%22%22%7D%7D" >&2

rm -f $jazzCookiesFile

echo $key


Comments
Liora Milbaum commented Aug 15 '16, 11:20 a.m.

 Amazing... Let me check it out.


Liora Milbaum commented Aug 15 '16, 12:37 p.m.

 what does $url stands for?


1
Michael Ricketts commented Aug 16 '16, 5:03 a.m.

Sorry, was copying lines out of a much longer script and missed that one :)
$url is the URL of the git repository, something like https://github.com/rickettm/repo


Liora Milbaum commented Aug 16 '16, 10:52 a.m.

 Thanks. I am almost done in porting your code to work on 6.0.2. Will post here the final code.


Sudhambarish V commented Jan 22 '20, 3:34 a.m. | edited Jan 22 '20, 4:41 a.m.

 Hi Michael and Liora,

I am trying to do the same for 6.0.6 But I am not able to register. Getting the below error

{
    "errorClass""java.lang.IllegalArgumentException",
    "errorMessage""\"The method 'GitRepositoryRegistrationRestService.postRegisterGitRepository()' has been supplied with an illegal argument\"",
    "errorCode"400
}


permanent link
Krzysztof Kaźmierczyk (7.4k34796) | answered Jan 22 '20, 4:40 a.m.

In newer CLM version you can do it automatically using the script provided by CLM team. Please refer to Registering and updating Git repositories by using scripts document.

Your answer


Register or to post your answer.