mirror of https://github.com/sipwise/repoapi.git
* tracker app, move everything related to WF or Mantis there * move settings to tracker: - REPOAPI_TRACKER -> TRACKER_PROVIDER - MANTIS_* -> TRACKER_MANTIS_* - WORKFRONT_* -> TRACKER_WORKFRONT_* Change-Id: If3eba4e86ec90d6cb4259104d0f474e936f70d43pull/9/head
parent
70d70da8c9
commit
16aadc64a1
@ -0,0 +1,85 @@
|
||||
{'note': {'id': 406459, 'reporter': {'id': 281, 'name': 'vseva', 'real_name': 'Victor Seva (Sipwise)', 'email': 'vseva@sipwise.com'
|
||||
}, 'text': 'hotfix fake_project.git fake_version triggered', 'view_state': {'id': 50, 'name': 'private', 'label': 'private'
|
||||
}, 'attachments': [], 'type': 'note', 'created_at': '2022-09-13T12: 10: 22+02: 00', 'updated_at': '2022-09-13T12: 10: 22+02: 00'
|
||||
}, 'issue': {'id': 13503, 'summary': 'Test custom support queue flag', 'description': 'is_support_queue should be true', 'project': {'id': 3, 'name': 'test project'
|
||||
}, 'category': {'id': 1, 'name': 'None'
|
||||
}, 'reporter': {'id': 125, 'name': 'gfuchs', 'real_name': 'Gernot Fuchs'
|
||||
}, 'handler': {'id': 125, 'name': 'gfuchs', 'real_name': 'Gernot Fuchs'
|
||||
}, 'status': {'id': 80, 'name': 'resolved', 'label': 'resolved', 'color': '#d2f5b0'
|
||||
}, 'resolution': {'id': 20, 'name': 'fixed', 'label': 'fixed'
|
||||
}, 'view_state': {'id': 10, 'name': 'public', 'label': 'public'
|
||||
}, 'priority': {'id': 30, 'name': 'P3-normal', 'label': 'P3-normal'
|
||||
}, 'severity': {'id': 50, 'name': 'minor', 'label': 'minor'
|
||||
}, 'reproducibility': {'id': 70, 'name': 'have not tried', 'label': 'have not tried'
|
||||
}, 'sticky': False, 'created_at': '2015-06-19T11: 01: 42+02: 00', 'updated_at': '2022-09-13T12: 10: 22+02: 00', 'notes': [
|
||||
{'id': 406459, 'reporter': {'id': 281, 'name': 'vseva', 'real_name': 'Victor Seva (Sipwise)', 'email': 'vseva@sipwise.com'
|
||||
}, 'text': 'hotfix fake_project.git fake_version triggered', 'view_state': {'id': 50, 'name': 'private', 'label': 'private'
|
||||
}, 'attachments': [], 'type': 'note', 'created_at': '2022-09-13T12: 10: 22+02: 00', 'updated_at': '2022-09-13T12: 10: 22+02: 00'
|
||||
}
|
||||
], 'custom_fields': [
|
||||
{'field': {'id': 11, 'name': 'Classification'
|
||||
}, 'value': ''
|
||||
},
|
||||
{'field': {'id': 23, 'name': 'Dev Related Tickets'
|
||||
}, 'value': ''
|
||||
},
|
||||
{'field': {'id': 7, 'name': 'Log Time'
|
||||
}, 'value': '0.5'
|
||||
},
|
||||
{'field': {'id': 24, 'name': 'NGCP Version'
|
||||
}, 'value': ''
|
||||
},
|
||||
{'field': {'id': 38, 'name': 'Product Version'
|
||||
}, 'value': ''
|
||||
},
|
||||
{'field': {'id': 52, 'name': 'Status Details'
|
||||
}, 'value': ''
|
||||
}
|
||||
], 'monitors': [
|
||||
{'id': 125, 'name': 'gfuchs', 'real_name': 'Gernot Fuchs'
|
||||
}
|
||||
], 'history': [
|
||||
{'created_at': '2015-06-19T11: 01: 42+02: 00', 'user': {'id': 125, 'name': 'gfuchs', 'real_name': 'Gernot Fuchs'
|
||||
}, 'type': {'id': 1, 'name': 'issue-new'
|
||||
}, 'message': 'New Issue'
|
||||
},
|
||||
{'created_at': '2015-06-19T11: 01: 42+02: 00', 'user': {'id': 125, 'name': 'gfuchs', 'real_name': 'Gernot Fuchs'
|
||||
}, 'type': {'id': 12, 'name': 'monitor-added'
|
||||
}, 'old_value': '125', 'new_value': '', 'message': 'Issue Monitored: Gernot Fuchs'
|
||||
},
|
||||
{'created_at': '2015-06-19T11: 05: 01+02: 00', 'user': {'id': 125, 'name': 'gfuchs', 'real_name': 'Gernot Fuchs'
|
||||
}, 'field': {'name': 'handler', 'label': 'Assigned To'
|
||||
}, 'type': {'id': 0, 'name': 'field-updated'
|
||||
}, 'old_value': {'id': 0
|
||||
}, 'new_value': {'id': 125, 'name': 'gfuchs', 'real_name': 'Gernot Fuchs'
|
||||
}, 'message': 'Assigned To', 'change': ' => Gernot Fuchs'
|
||||
},
|
||||
{'created_at': '2015-06-19T11: 05: 01+02: 00', 'user': {'id': 125, 'name': 'gfuchs', 'real_name': 'Gernot Fuchs'
|
||||
}, 'field': {'name': 'status', 'label': 'Status'
|
||||
}, 'type': {'id': 0, 'name': 'field-updated'
|
||||
}, 'old_value': {'id': 10, 'name': 'new', 'label': 'new', 'color': '#fcbdbd'
|
||||
}, 'new_value': {'id': 50, 'name': 'assigned', 'label': 'assigned', 'color': '#c2dfff'
|
||||
}, 'message': 'Status', 'change': 'new => assigned'
|
||||
},
|
||||
{'created_at': '2015-06-19T11: 05: 09+02: 00', 'user': {'id': 125, 'name': 'gfuchs', 'real_name': 'Gernot Fuchs'
|
||||
}, 'field': {'name': 'status', 'label': 'Status'
|
||||
}, 'type': {'id': 0, 'name': 'field-updated'
|
||||
}, 'old_value': {'id': 50, 'name': 'assigned', 'label': 'assigned', 'color': '#c2dfff'
|
||||
}, 'new_value': {'id': 80, 'name': 'resolved', 'label': 'resolved', 'color': '#d2f5b0'
|
||||
}, 'message': 'Status', 'change': 'assigned => resolved'
|
||||
},
|
||||
{'created_at': '2015-06-19T11: 05: 09+02: 00', 'user': {'id': 125, 'name': 'gfuchs', 'real_name': 'Gernot Fuchs'
|
||||
}, 'field': {'name': 'resolution', 'label': 'Resolution'
|
||||
}, 'type': {'id': 0, 'name': 'field-updated'
|
||||
}, 'old_value': {'id': 10, 'name': 'open', 'label': 'open'
|
||||
}, 'new_value': {'id': 20, 'name': 'fixed', 'label': 'fixed'
|
||||
}, 'message': 'Resolution', 'change': 'open => fixed'
|
||||
},
|
||||
{'created_at': '2022-09-13T12: 10: 22+02: 00', 'user': {'id': 281, 'name': 'vseva', 'real_name': 'Victor Seva (Sipwise)'
|
||||
}, 'type': {'id': 2, 'name': 'note-added'
|
||||
}, 'note': {'id': 406459
|
||||
}, 'message': 'Note Added: 0406459'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,35 @@
|
||||
# Generated by Django 3.2.15 on 2022-09-13 17:33
|
||||
from django.db import migrations
|
||||
from django.db import models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("repoapi", "0012_ldap_grp_perms"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name="MantisNoteInfo",
|
||||
fields=[
|
||||
(
|
||||
"id",
|
||||
models.AutoField(
|
||||
auto_created=True,
|
||||
primary_key=True,
|
||||
serialize=False,
|
||||
verbose_name="ID",
|
||||
),
|
||||
),
|
||||
("mantis_id", models.CharField(max_length=50)),
|
||||
("gerrit_change", models.CharField(max_length=50)),
|
||||
("eventtype", models.CharField(max_length=50)),
|
||||
],
|
||||
options={
|
||||
"unique_together": {
|
||||
("mantis_id", "gerrit_change", "eventtype")
|
||||
},
|
||||
},
|
||||
),
|
||||
]
|
||||
@ -0,0 +1,65 @@
|
||||
# Copyright (C) 2015-2022 The Sipwise Team - http://sipwise.com
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License as published by the Free
|
||||
# Software Foundation, either version 3 of the License, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
# more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along
|
||||
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
from django.test import override_settings
|
||||
|
||||
from repoapi.models.wni import MantisNoteInfo
|
||||
from repoapi.models.wni import NoteInfo
|
||||
from repoapi.models.wni import WorkfrontNoteInfo
|
||||
from repoapi.test.base import BaseTest
|
||||
from tracker.conf import Tracker
|
||||
|
||||
|
||||
@override_settings(TRACKER_PROVIDER=Tracker.WORKFRONT)
|
||||
class WorkfrontNoteTestCase(BaseTest):
|
||||
def test_get_model(self):
|
||||
self.assertIs(NoteInfo.get_model(), WorkfrontNoteInfo)
|
||||
|
||||
def test_getID(self):
|
||||
res = WorkfrontNoteInfo.getIds("jojo TT#0891 whatever")
|
||||
self.assertCountEqual(res, ["0891"])
|
||||
|
||||
def test_getID_multiple(self):
|
||||
res = WorkfrontNoteInfo.getIds("jojo TT#0891 whatever TT#0001")
|
||||
self.assertCountEqual(res, ["0891", "0001"])
|
||||
|
||||
def test_getID_multiple_duplicate(self):
|
||||
res = WorkfrontNoteInfo.getIds("jojo TT#0891 whatever TT#0001 TT#0891")
|
||||
self.assertCountEqual(res, ["0891", "0001"])
|
||||
|
||||
def test_getCommit(self):
|
||||
res = WorkfrontNoteInfo.getCommit("1234567 TT#67676 whatever")
|
||||
self.assertEqual(res, "1234567")
|
||||
|
||||
|
||||
@override_settings(TRACKER_PROVIDER=Tracker.MANTIS)
|
||||
class MantisNoteTestCase(BaseTest):
|
||||
def test_get_model(self):
|
||||
self.assertIs(NoteInfo.get_model(), MantisNoteInfo)
|
||||
|
||||
def test_getID(self):
|
||||
res = MantisNoteInfo.getIds("jojo TT#0891 MT#123 whatever")
|
||||
self.assertCountEqual(res, ["123"])
|
||||
|
||||
def test_getID_multiple(self):
|
||||
res = MantisNoteInfo.getIds("jojo MT#0891 whatever MT#0001")
|
||||
self.assertCountEqual(res, ["0891", "0001"])
|
||||
|
||||
def test_getID_multiple_duplicate(self):
|
||||
res = MantisNoteInfo.getIds("jojo MT#0891 whatever MT#0001 MT#0891")
|
||||
self.assertCountEqual(res, ["0891", "0001"])
|
||||
|
||||
def test_getCommit(self):
|
||||
res = MantisNoteInfo.getCommit("1234567 TT#67676 MT#1234 whatever")
|
||||
self.assertEqual(res, "1234567")
|
||||
@ -0,0 +1,23 @@
|
||||
# Copyright (C) 2022 The Sipwise Team - http://sipwise.com
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License as published by the Free
|
||||
# Software Foundation, either version 3 of the License, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
# more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along
|
||||
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class TrackerConfig(AppConfig):
|
||||
default_auto_field = "django.db.models.BigAutoField"
|
||||
name = "tracker"
|
||||
|
||||
def ready(self):
|
||||
from .conf import settings # noqa
|
||||
@ -0,0 +1,46 @@
|
||||
# Copyright (C) 2022 The Sipwise Team - http://sipwise.com
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License as published by the Free
|
||||
# Software Foundation, either version 3 of the License, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
# more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along
|
||||
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
from enum import Enum, unique
|
||||
from django.conf import settings # noqa
|
||||
from appconf import AppConf
|
||||
|
||||
|
||||
@unique
|
||||
class Tracker(Enum):
|
||||
NONE = "None"
|
||||
MANTIS = "Mantis"
|
||||
WORKFRONT = "WorkFront"
|
||||
|
||||
|
||||
class TrackerConf(AppConf):
|
||||
REGEX = {
|
||||
Tracker.NONE: r"#(\d+)",
|
||||
Tracker.WORKFRONT: r"TT#(\d+)",
|
||||
Tracker.MANTIS: r"MT#(\d+)",
|
||||
}
|
||||
ARTIFACT_JOB_REGEX = [
|
||||
".*-repos$",
|
||||
]
|
||||
WORKFRONT_CREDENTIALS = "fake.txt"
|
||||
MANTIS_URL = "https://support.local/api/rest/{}"
|
||||
MANTIS_TOKEN = "fake_mantis_token"
|
||||
MANTIS_TARGET_RELEASE = {
|
||||
"id": 75,
|
||||
"name": "Target Release",
|
||||
}
|
||||
PROVIDER = Tracker.MANTIS
|
||||
|
||||
class Meta:
|
||||
prefix = "tracker"
|
||||
File diff suppressed because one or more lines are too long
@ -0,0 +1,76 @@
|
||||
# Copyright (C) 2022 The Sipwise Team - http://sipwise.com
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License as published by the Free
|
||||
# Software Foundation, either version 3 of the License, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
# more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along
|
||||
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
import re
|
||||
|
||||
from django.db import models
|
||||
|
||||
from . import utils
|
||||
from .conf import Tracker
|
||||
from .conf import TrackerConf
|
||||
|
||||
tracker_settings = TrackerConf()
|
||||
|
||||
|
||||
class TrackerInfo(models.Model):
|
||||
tracker_re = re.compile(tracker_settings.REGEX[Tracker.NONE])
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
@classmethod
|
||||
def getIds(cls, change):
|
||||
"""
|
||||
parses text searching for tracker occurrences
|
||||
returns a list of IDs
|
||||
"""
|
||||
if change:
|
||||
res = cls.tracker_re.findall(change)
|
||||
return set(res)
|
||||
else:
|
||||
return set()
|
||||
|
||||
@property
|
||||
def field_id(self):
|
||||
return getattr(self, self.field_id_name)
|
||||
|
||||
|
||||
class WorkfrontInfo(TrackerInfo):
|
||||
workfront_id = models.CharField(max_length=50, null=False)
|
||||
tracker_re = re.compile(tracker_settings.REGEX[Tracker.WORKFRONT])
|
||||
field_id_name = "workfront_id"
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
def send(self, msg: str):
|
||||
return utils.workfront_note_send(self.workfront_id, msg)
|
||||
|
||||
def set_target_release(self, release):
|
||||
return utils.workfront_set_release_target(self.workfront_id, release)
|
||||
|
||||
|
||||
class MantisInfo(TrackerInfo):
|
||||
mantis_id = models.CharField(max_length=50, null=False)
|
||||
tracker_re = re.compile(tracker_settings.REGEX[Tracker.MANTIS])
|
||||
field_id_name = "mantis_id"
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
def send(self, msg: str):
|
||||
return utils.mantis_note_send(self.mantis_id, msg)
|
||||
|
||||
def set_target_release(self, release):
|
||||
return utils.mantis_set_release_target(self.mantis_id, release)
|
||||
@ -0,0 +1,86 @@
|
||||
# Copyright (C) 2022 The Sipwise Team - http://sipwise.com
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License as published by the Free
|
||||
# Software Foundation, either version 3 of the License, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
# more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along
|
||||
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
import json
|
||||
from unittest.mock import patch
|
||||
|
||||
from django.conf import settings
|
||||
from django.test import SimpleTestCase
|
||||
|
||||
from tracker import utils
|
||||
from tracker.conf import TrackerConf
|
||||
|
||||
FIXTURES_PATH = settings.BASE_DIR.joinpath("tracker", "fixtures")
|
||||
MANTIS_ISSUE_JSON = FIXTURES_PATH.joinpath("mantis_issue.json")
|
||||
MANTIS_ISSUE_ID = 36018
|
||||
|
||||
tracker_settings = TrackerConf()
|
||||
|
||||
|
||||
class FakeResponse(object):
|
||||
def __init__(self, filepath):
|
||||
self.filepath = filepath
|
||||
|
||||
def json(self):
|
||||
with self.filepath.open() as f:
|
||||
res = json.load(f)
|
||||
return res
|
||||
|
||||
|
||||
class TestFakeResponse(SimpleTestCase):
|
||||
def test_json(self):
|
||||
fake = FakeResponse(MANTIS_ISSUE_JSON)
|
||||
res = fake.json()
|
||||
self.assertTrue(len(res["issues"]), 1)
|
||||
self.assertEqual(res["issues"][0]["id"], MANTIS_ISSUE_ID)
|
||||
|
||||
|
||||
def set_target_release_value(issue, value):
|
||||
cf = issue["custom_fields"]
|
||||
for val in cf:
|
||||
if val["field"]["id"] == tracker_settings.MANTIS_TARGET_RELEASE["id"]:
|
||||
val["value"] = value
|
||||
|
||||
|
||||
class TestUtils(SimpleTestCase):
|
||||
@patch(
|
||||
"tracker.utils.mantis_query",
|
||||
return_value=FakeResponse(MANTIS_ISSUE_JSON),
|
||||
)
|
||||
def test_mantis_get_issue_ok(self, mq):
|
||||
res = utils.mantis_get_issue(MANTIS_ISSUE_ID)
|
||||
self.assertEqual(res["id"], MANTIS_ISSUE_ID)
|
||||
mq.assert_called_once_with(
|
||||
"GET", "https://support.local/api/rest/issues/36018"
|
||||
)
|
||||
|
||||
def test_mantis_get_issue_id(self):
|
||||
fake = FakeResponse(MANTIS_ISSUE_JSON)
|
||||
res = utils.mantis_get_issue_id(fake.json(), MANTIS_ISSUE_ID)
|
||||
self.assertEqual(res["id"], MANTIS_ISSUE_ID)
|
||||
|
||||
def test_mantis_get_target_releases(self):
|
||||
fake = FakeResponse(MANTIS_ISSUE_JSON)
|
||||
issue = utils.mantis_get_issue_id(fake.json(), MANTIS_ISSUE_ID)
|
||||
set_target_release_value(issue, "mr10.1")
|
||||
res = utils.mantis_get_target_releases(issue)
|
||||
self.assertListEqual(res, ["mr10.1"])
|
||||
|
||||
set_target_release_value(issue, "mr10.1, mr8.5.1")
|
||||
res = utils.mantis_get_target_releases(issue)
|
||||
self.assertListEqual(res, ["mr8.5.1", "mr10.1"])
|
||||
|
||||
set_target_release_value(issue, "mr10.1, mr8.5.1,,")
|
||||
res = utils.mantis_get_target_releases(issue)
|
||||
self.assertListEqual(res, ["mr8.5.1", "mr10.1"])
|
||||
@ -0,0 +1,131 @@
|
||||
# Copyright (C) 2022 The Sipwise Team - http://sipwise.com
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License as published by the Free
|
||||
# Software Foundation, either version 3 of the License, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
# more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along
|
||||
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
import json
|
||||
|
||||
import requests
|
||||
import structlog
|
||||
from natsort import humansorted
|
||||
|
||||
from .conf import TrackerConf
|
||||
from .exceptions import IssueNotFound
|
||||
from repoapi.utils import executeAndReturnOutput
|
||||
|
||||
tracker_settings = TrackerConf()
|
||||
logger = structlog.get_logger(__name__)
|
||||
|
||||
MANTIS_HEADERS = {
|
||||
"Authorization": tracker_settings.MANTIS_TOKEN,
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
|
||||
|
||||
def workfront_note_send(_id, message):
|
||||
command = [
|
||||
"/usr/bin/workfront-jenkins-update",
|
||||
"--credfile=%s" % tracker_settings.WORKFRONT_CREDENTIALS,
|
||||
"--taskid=%s" % _id,
|
||||
'--message="%s"' % message,
|
||||
]
|
||||
res = executeAndReturnOutput(command)
|
||||
if res[0] != 0:
|
||||
logger.error(
|
||||
"can't post workfront notes", stdout=res[1], stderr=res[2]
|
||||
)
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def workfront_set_release_target(_id, release):
|
||||
command = [
|
||||
"/usr/bin/workfront-target-task",
|
||||
"--credfile=%s" % tracker_settings.WORKFRONT_CREDENTIALS,
|
||||
"--taskid=%s" % _id,
|
||||
"--release=%s" % release,
|
||||
]
|
||||
res = executeAndReturnOutput(command)
|
||||
if res[0] != 0:
|
||||
logger.error("can't set release target", stdout=res[1], stderr=res[2])
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def mantis_query(method, url, payload=None) -> requests.Response:
|
||||
logger.bind(
|
||||
method=method,
|
||||
url=url,
|
||||
payload=payload,
|
||||
)
|
||||
response = requests.request(
|
||||
f"{method}", url, headers=MANTIS_HEADERS, data=payload
|
||||
)
|
||||
response.raise_for_status()
|
||||
return response
|
||||
|
||||
|
||||
def mantis_get_issue_id(res, _id: int):
|
||||
for issue in res["issues"]:
|
||||
if issue["id"] == _id:
|
||||
return issue
|
||||
|
||||
|
||||
def mantis_get_issue(_id: int):
|
||||
url = tracker_settings.MANTIS_URL.format(f"issues/{_id}")
|
||||
response = mantis_query("GET", url)
|
||||
res = mantis_get_issue_id(response.json(), _id)
|
||||
if res:
|
||||
return res
|
||||
raise IssueNotFound(f"{_id} Not found in response")
|
||||
|
||||
|
||||
def mantis_note_send(_id: int, message: str) -> requests.Response:
|
||||
url = tracker_settings.MANTIS_URL.format(f"issues/{_id}/notes")
|
||||
payload = json.dumps(
|
||||
{"text": f"{message}", "view_state": {"name": "private"}}
|
||||
)
|
||||
return mantis_query("POST", url, payload)
|
||||
|
||||
|
||||
def mantis_get_target_releases(issue) -> list:
|
||||
cf = issue["custom_fields"]
|
||||
res = set()
|
||||
for val in cf:
|
||||
if val["field"]["id"] == tracker_settings.MANTIS_TARGET_RELEASE["id"]:
|
||||
for word in val["value"].split(","):
|
||||
word = word.strip()
|
||||
if word:
|
||||
res.add(word)
|
||||
break
|
||||
return humansorted(res)
|
||||
|
||||
|
||||
def mantis_set_release_target(_id: int, release: str) -> requests.Response:
|
||||
issue = mantis_get_issue(_id)
|
||||
releases = mantis_get_target_releases(issue)
|
||||
url = tracker_settings.MANTIS_URL.format(f"issues/{_id}")
|
||||
cf = tracker_settings.MANTIS_TARGET_RELEASE
|
||||
payload = json.dumps(
|
||||
{
|
||||
"custom_fields": [
|
||||
{
|
||||
"field": {
|
||||
"id": cf["id"],
|
||||
"name": cf["name"],
|
||||
},
|
||||
"value": f"{releases}",
|
||||
},
|
||||
]
|
||||
}
|
||||
)
|
||||
return mantis_query("PATCH", url, payload)
|
||||
Loading…
Reference in new issue