swingbit / jira2gitlab

Migrate Jira projects into a Gitlab instance
MIT License
20 stars 11 forks source link

Cannot create gitlab issue- Client Error forbidden #6

Closed caseybea closed 1 year ago

caseybea commented 1 year ago

Hello! I am hoping to use your code to import our old JIRA iissues into GitLab. There are a few of these out there, but yours feels like it's the most mature and feature-rich one out there.

I have the project in gitlab set up, the access token set up- with "project owner" rights, and "admin" rights within gitlab.

But something is still preventing the script from actually creating the issue(s). Wondering if you have an idea and can assist?

This is how far I'm getting (below). It's reading all the jira issues, and even finding and mapping the admin rights of the two users found in the first issue I have in JIRA. But when it actually goes to CREATE the issue, I am getting a weird access denied issue:

[root@butler jira2gitlab-main]# ./jira2gitlab.py

Migrating ITS to kent-test-group/it-support [INFO] Loading Jira issues from project ITS ... 2311 <==== successfully reads all the jira issues

[INFO] #1/2311 Migrating Jira issue ITS-1 ... data: {'created_at': '2007-09-20T10:58:15.000-0500', 'assignee_ids': ['btaylor'], 'title': '[ITS-1] Directory creation request for rgddev and rgd servers', 'description': 'We need a directory to publish web sites for labs.rgd.mcw.edu and labsdev.rgd.mcw.edu . May I suggest the creation of the following directories on rgddev.mcw.edu and rgd.mcw.edu machines for publishing these sites to: \n /usr/local/apache2/labs_htdocs \nowned by the user apache. \nthanks \nGeorge\n\n___\n\nImported from Jira issue ITS-1\n\n', 'milestone_id': None, 'labels': 'jira-import, T::task, P::trivial, unix request'} ... Traceback (most recent call last): File "./jira2gitlab.py", line 569, in migrate_project gl_issue.raise_for_status() File "/usr/lib/python3.6/site-packages/requests/models.py", line 940, in raise_for_status raise HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://gitlab.ctsi.mcw.edu/api/v4/projects/10/issues

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "./jira2gitlab.py", line 882, in migrate_project(jira_project, gitlab_project) File "./jira2gitlab.py", line 572, in migrate_project raise Exception(f"Unable to create Gitlab issue for Jira issue {issue['key']}\n{e}") Exception: Unable to create Gitlab issue for Jira issue ITS-1 403 Client Error: Forbidden for url: https://gitlab.ctsi.mcw.edu/api/v4/projects/10/issues

Migration failed

Resetting user privileges..

swingbit commented 1 year ago

Hi @caseybea ,

I think this is happening because throughout the code I assumed user root would be used in Gitlab to create issues. You are using a token for an admin user that is not root, if I understand well.

I will push a fix, hopefully today.

Also, I see now that I had a number of fixes never pushed. Please wait for them.

swingbit commented 1 year ago

@caseybea This should do (including then fixes not previously pushed).

You can now choose which admin user to use, in jira2gitlab_secrets.py.

Note: I still recommend to use the default Administrator user (which internally is called root).

caseybea commented 1 year ago

Oh my gosh- so YES that was the issue. ALSO, I was using a "Proect Token" and not a "personal token". I'm new to this, did not know there were two types. I of course am just using "root" so I know it will work. How to set up the token is not mentioned at alll in your documentation so I missed that little tidbit!

The script plowed through just over 300 issues, then unfortunately choked. (NOTE: What I see imported thus far looks AMAZING, wow).

I am submitting a different issue on that and hope you might have an idea. This jira migration script, if I can get it to finish, is the best thing EVER. BYEBYE Atlassian..........