示例#1
0
    def _add_label_to_tracker(self, story_id, label):
        method = '_add_label_to_tracker'
        commons.printMSG(Tracker.clazz, method, 'begin')

        label_to_post = Object()
        label_to_post.name = label.lower()

        tracker_url = "{url}/services/v5/projects/{projid}/stories/{storyid}/labels".format(url=Tracker.tracker_url,
                                                                                            projid=Tracker.project_id,
                                                                                            storyid=story_id)

        headers = {'Content-type': 'application/json', 'Accept': 'application/json', 'X-TrackerToken': Tracker.token}

        commons.printMSG(Tracker.clazz, method, tracker_url)
        commons.printMSG(Tracker.clazz, method, label_to_post.to_JSON())

        try:
            resp = requests.post(tracker_url, label_to_post.to_JSON(), headers=headers, timeout=self.http_timeout)
        except requests.ConnectionError:
            commons.printMSG(Tracker.clazz, method, 'Request to Tracker timed out.', 'WARN')
        except Exception as e:
            commons.printMSG(Tracker.clazz, method, "Unable to tag story {story} with label {lbl}".format(
                story=story_id, lbl=label), 'WARN')
            commons.printMSG(Tracker.clazz, method, e, 'WARN')

        if resp.status_code != 200:
            commons.printMSG(Tracker.clazz, method, "Unable to tag story {story} with label {lbl} \r\n "
                                                    "Response: {response}".format(story=story_id, lbl=label,
                                                                                  response=resp.text), 'WARN')
        else:
            commons.printMSG(Tracker.clazz, method, resp.text)

        commons.printMSG(Tracker.clazz, method, 'end')
示例#2
0
    def _add_version_to_jira_story(self, story_id, label):
        method = '_add_version_to_jira_story'
        commons.print_msg(Jira.clazz, method, 'begin')

        detail = self._retrieve_story_detail(story_id)

        versions = detail.versions
        versions.append(label)

        add_version_story = Object()
        add_version_story.update = Object()
        add_version_story.update.fixVersions = []
        set_version = Object()
        set_version.set = []
        for current_version in versions:
            version = Object()
            version.name = current_version
            set_version.set.append(version)
        add_version_story.update.fixVersions.append(set_version)

        jira_url = "{url}/rest/api/2/issue/{storyid}".format(url=Jira.jira_url,
                                                             storyid=story_id)

        headers = {
            'Content-type': 'application/json',
            'Accept': 'application/json'
        }

        commons.print_msg(Jira.clazz, method, jira_url)
        commons.print_msg(Jira.clazz, method, add_version_story.to_JSON())

        try:
            # TODO: Remove auth from below...
            resp = requests.put(jira_url,
                                add_version_story.to_JSON(),
                                auth=(os.getenv('JIRA_USER'),
                                      os.getenv('JIRA_PWD')),
                                headers=headers,
                                timeout=self.http_timeout)

            if resp.status_code != 204:
                commons.print_msg(
                    Jira.clazz, method,
                    "Unable to tag story {story} with label {lbl} \r\n "
                    "Response: {response}".format(story=story_id,
                                                  lbl=label,
                                                  response=resp.text), 'WARN')
            else:
                commons.print_msg(Jira.clazz, method, resp.text)
        except requests.ConnectionError as e:
            commons.print_msg(Jira.clazz, method,
                              'Connection error. ' + str(e), 'WARN')
        except Exception as e:
            commons.print_msg(
                Jira.clazz, method,
                "Unable to tag story {story} with label {lbl}".format(
                    story=story_id, lbl=label), 'WARN')
            commons.print_msg(Jira.clazz, method, e, 'WARN')

        commons.print_msg(Jira.clazz, method, 'end')
示例#3
0
    def add_tag_and_release_notes_to_github(self, new_version_tag_array, release_notes=None):
        # TODO this needs to be split out and better unit testing added.
        # testing is hard because json attributes are not ordered.

        method = 'add_tag_and_release_notes_to_github'
        commons.printMSG(GitHub.clazz, method, 'begin')

        me = Object()
        me.tag_name = self.convert_semver_tag_array_to_semver_string(new_version_tag_array)
        me.target_commitish = self.config.build_env_info['associatedBranchName']
        me.name = self.convert_semver_tag_array_to_semver_string(new_version_tag_array)

        if release_notes is not None and len(release_notes) > 0:
            me.body = release_notes
        else:
            me.body = 'No Release Notes'

        me.draft = False
        me.prerelease = True

        # release builds will have a build index of 0.
        if self._is_semver_tag_array_release_or_snapshot(new_version_tag_array) == 'release':
            me.prerelease = False

        tag_and_release_note_payload = me.to_JSON()

        url_params = {'org': self.org, 'repo': self.repo}
        commons.printMSG(GitHub.clazz, method, self.url)
        commons.printMSG(GitHub.clazz, method, self.org)
        commons.printMSG(GitHub.clazz, method, self.repo)

        release_url = self.url + '/' + self.org + '/' + self.repo + '/releases'

        commons.printMSG(GitHub.clazz, method, release_url)
        commons.printMSG(GitHub.clazz, method, tag_and_release_note_payload)
        commons.printMSG(GitHub.clazz, method, ("?", url_params))

        if self.token is not None:
            headers = {'Content-type': cicommons.content_json, 'Accept': cicommons.content_json, 'Authorization': ('token ' + self.token)}
        else:
            headers = {'Content-type': cicommons.content_json, 'Accept': cicommons.content_json}

        try:
            resp = requests.post(release_url, tag_and_release_note_payload, headers=headers, params=url_params, verify=False, timeout=self.http_timeout)
        except requests.ConnectionError:
            commons.printMSG(GitHub.clazz, method, 'Request to GitHub timed out.', 'ERROR')
            exit(1)
        except:
            commons.printMSG(GitHub.clazz, method, "The github add release notes call failed to {} has failed".format(
                release_url), 'ERROR')
            exit(1)

        if resp.status_code != 200 and resp.status_code != 201:
            commons.printMSG(GitHub.clazz, method, "The github add release notes call failed to {url}\r\n Response: {"
                                                   "rsp}".format(url=release_url, rsp=resp.text), 'ERROR')
            exit(1)
        else:
            commons.printMSG(GitHub.clazz, method, resp.text)

        commons.printMSG(GitHub.clazz, method, 'end')
示例#4
0
    def _create_version(self, version, released=False):
        method = '_create_version'
        commons.print_msg(Jira.clazz, method, 'begin')

        new_version = Object()
        new_version.description = "Generated from pipeline"
        new_version.name = version
        if released:
            new_version.userReleaseDate = datetime.datetime.now().strftime(
                "%-d/%b/%Y")
        new_version.project = Jira.project_id
        new_version.released = released

        jira_url = "{}/rest/api/2/version".format(Jira.jira_url)

        headers = {'Content-type': 'application/json'}

        commons.print_msg(Jira.clazz, method, jira_url)
        commons.print_msg(Jira.clazz, method, new_version.to_JSON())

        try:
            # TODO: Remove auth from below...
            resp = requests.post(jira_url,
                                 new_version.to_JSON(),
                                 headers=headers,
                                 auth=(os.getenv('JIRA_USER'),
                                       os.getenv('JIRA_PWD')),
                                 timeout=self.http_timeout)

            if resp.status_code != 201:
                commons.print_msg(
                    Jira.clazz, method, "Unable to add version {version} \r\n "
                    "Response: {response}".format(version=version,
                                                  response=resp.text), 'WARN')
            else:
                commons.print_msg(Jira.clazz, method, resp.text)
        except requests.ConnectionError as e:
            commons.print_msg(Jira.clazz, method,
                              'Connection error. ' + str(e), 'WARN')
        except Exception as e:
            commons.print_msg(
                Jira.clazz, method,
                "Unable to add version {verions}".format(version=version),
                'WARN')
            commons.print_msg(Jira.clazz, method, e, 'WARN')

        commons.print_msg(Jira.clazz, method, 'end')