Verified Commit bc770498 authored by Agate's avatar Agate 💬

Store more information on models

parent 3f31a79a
......@@ -19,6 +19,7 @@ class Contributor(models.Model):
CONTRIBUTION_TYPES = [
("dev", "Development"),
("dev:issue", "Development/Issue"),
("i18n", "Translations"),
("network", "Network"),
("donation", "Donations"),
......
import requests
import pendulum
import urllib.parse
from django.utils import timezone
......@@ -40,18 +41,25 @@ def import_contributor_from_author(payload):
return contributor
def import_issue_as_contribution(payload):
def import_issue_as_contribution(payload, project_name):
contributor = import_contributor_from_author(payload["author"])
parsed_url = urllib.parse.urlparse(payload["_links"]["self"])
project_url = f"{parsed_url.scheme}://{parsed_url.netloc}/{project_name}"
external_id = payload["_links"]["self"]
defaults = {
"summary": payload["title"],
"contributor": contributor,
"type": "dev",
"type": "dev:issue",
"creation_date": pendulum.parse(payload["created_at"]),
"import_date": timezone.now(),
"is_visible": True,
"url": payload["web_url"],
"metadata": {"labels": payload["labels"]},
"metadata": {
"labels": payload["labels"],
"id": payload["iid"],
"project": project_name,
"project_url": project_url,
},
}
return core_models.Contribution.objects.update_or_create(
......
......@@ -17,6 +17,7 @@ def test_retrieve_issue(requests_mock):
def test_import_issue_as_contribution(now, db):
project_name = "awesome/project"
issue_payload = {
"id": 703,
"iid": 559,
......@@ -35,7 +36,7 @@ def test_import_issue_as_contribution(now, db):
"_links": {"self": "https://gitlab.test/api/v4/projects/17/issues/559"},
}
contribution = gitlab.import_issue_as_contribution(issue_payload)
contribution = gitlab.import_issue_as_contribution(issue_payload, project_name)
contributor = contribution.contributor
......@@ -44,13 +45,18 @@ def test_import_issue_as_contribution(now, db):
assert contributor.metadata == {"gitlab": issue_payload["author"]}
assert contribution.summary == issue_payload["title"]
assert contribution.type == "dev"
assert contribution.type == "dev:issue"
assert contribution.creation_date == pendulum.parse(issue_payload["created_at"])
assert contribution.import_date == now
assert contribution.is_visible is True
assert contribution.external_id == issue_payload["_links"]["self"]
assert contribution.url == issue_payload["web_url"]
assert contribution.metadata == {"labels": issue_payload["labels"]}
assert contribution.metadata == {
"labels": issue_payload["labels"],
"id": issue_payload["iid"],
"project": project_name,
"project_url": f"https://gitlab.test/{project_name}",
}
def test_import_contributor_create(db):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment