From 856f98108f338e6379ed0d2aff0e97654007f9df Mon Sep 17 00:00:00 2001 From: Athos Ribeiro Date: Dec 04 2016 00:09:15 +0000 Subject: [PATCH 1/2] Fix attachment name comparison The attachment list was being tested for membership against a dict. This is not allowed and would raise a "unhashable type: 'list'" TypeError. --- diff --git a/pagure_importer/utils/importer_trac.py b/pagure_importer/utils/importer_trac.py index f280e8a..ef0eb4c 100644 --- a/pagure_importer/utils/importer_trac.py +++ b/pagure_importer/utils/importer_trac.py @@ -94,7 +94,8 @@ class TracImporter(): # add all the comments to the issue object for key in comments: if comments[key].attachment is not None and \ - comments[key].attachment in pagure_issue.attachment: + any(attachment in comments[key].attachment for attachment in + pagure_issue.attachment): project = repo_name.replace('.git', '') for attach_name in comments[key].attachment: filename = get_secure_filename( From 67e46b6b9fe134ea1c8fd565bf4c8b2161dff23f Mon Sep 17 00:00:00 2001 From: Athos Ribeiro Date: Dec 04 2016 00:09:31 +0000 Subject: [PATCH 2/2] Fix links for attachments in group projects Attachment links were set only in the project namespace: that is not true when the repository belongs to a group or to a fork. This commit extracts the whole namespace from the git remote link after cloning the tickets repository. --- diff --git a/pagure_importer/utils/__init__.py b/pagure_importer/utils/__init__.py index ee0d085..db77333 100644 --- a/pagure_importer/utils/__init__.py +++ b/pagure_importer/utils/__init__.py @@ -2,6 +2,8 @@ import csv import os import json import click +import urlparse +import pygit2 from configparser import ConfigParser from github import Github from github.GithubException import TwoFactorException @@ -172,3 +174,18 @@ def gh_get_user_email(name): else: raise EmailNotFound('You need to fill out all the emails of' ' the issue commentors') + + +def get_pagure_namespace(repo_folder, repo_name): + ''' returns pagure namespace in the following format: + GROUP/PROJECT + ''' + + repo_path = os.path.join(repo_folder, repo_name) + repo = pygit2.Repository(repo_path) + remote_url = repo.remotes['origin'].url + remote_path = urlparse.urlparse(remote_url).path + remote_path = remote_path.replace('.git', '') + namespace_list = remote_path.split('/')[2:] + namespace = '/'.join(namespace_list) + return namespace diff --git a/pagure_importer/utils/importer_trac.py b/pagure_importer/utils/importer_trac.py index ef0eb4c..d4c844c 100644 --- a/pagure_importer/utils/importer_trac.py +++ b/pagure_importer/utils/importer_trac.py @@ -6,6 +6,7 @@ import click import requests from datetime import datetime +from pagure_importer.utils import get_pagure_namespace from pagure_importer.utils.git import ( clone_repo, get_secure_filename, push_delete_repo, update_git) from pagure_importer.utils.models import User, Issue, IssueComment @@ -96,7 +97,8 @@ class TracImporter(): if comments[key].attachment is not None and \ any(attachment in comments[key].attachment for attachment in pagure_issue.attachment): - project = repo_name.replace('.git', '') + project = get_pagure_namespace(repo_folder, repo_name) + for attach_name in comments[key].attachment: filename = get_secure_filename( pagure_issue.attachment[attach_name], attach_name)