issuetracker.py 2.26 KB
Newer Older
Nicolas Gelot's avatar
Nicolas Gelot committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
from tcms.core.contrib.linkreference.models import LinkReference
from tcms.issuetracker import types


class Gitlab(types.Gitlab):
    def report_issue_from_testexecution(self, execution, user):
        repo_id = self.it_class.repo_id(self.bug_system)
        project = self.rpc.projects.get(repo_id)
        new_issue = project.issues.create(
            {
                "title": f"Failed test: {execution.case.summary}",
                "description": self._report_comment(execution),
            }
        )

        # and also add a link reference that will be shown in the UI
        LinkReference.objects.get_or_create(
            execution=execution,
            url=new_issue.attributes["web_url"],
            is_defect=True,
        )
        return new_issue.attributes["web_url"]

    def fetch_username(self, execution):
        """Try to match kiwi and gitlab username"""
        for attr in ["username", "email"]:
            username = getattr(execution.assignee, attr)
            users = self.rpc.users.list(search=username)
            if len(users) == 1:
                return users[0].username
        return None

    def _report_comment(self, execution):
        """
        Returns the comment which is used in the original defect report.
        """
        username = self.fetch_username(execution)
        username = f"@{username}" if username else "unkown"
        comment = f"""
- /e/ version: {execution.build.name}
- Device model(s):
- Device rooted: yes/no

## Summary

Filed from execution {execution.get_full_url()} and reported by {username}

## The problem

**Steps to reproduce**

Run the test case [{execution.case.summary}]({execution.case.get_full_url()})

**What is the current behavior?**

This test case fails with build {execution.build.name}

**What is the expected correct behavior?**

<What you should see instead>

## Technical informations

**Relevant logs (`adb logcat`)**

<Paste any relevant logs in the codeblock bellow>

```

```

**Relevant screenshots**

<Screenshots of the problem>

## Solutions

**Workaround**

<To get the feature working or at least to make the device usable>

**Possible fixes**

<Any idea to fix the issue or a link to the line of code that might be the cause for this problem>

/label ~Bug

"""  # noqa: E501
        return comment