Example #1
0
    def test_get_commit_id_from_ref_404(self):
        """
        Attempt to fetch a branch that has been deleted
        """
        responses.add(
            responses.GET, 'https://api.github.com/repos/edx/edx-platform/git/refs/heads/deleted-branch',
            body=json.dumps({'message': 'Not Found'}),
            content_type='application/json; charset=utf8',
            status=404)

        with self.assertRaises(github.ObjectDoesNotExist):
            github.get_commit_id_from_ref('edx/edx-platform', 'deleted-branch')
Example #2
0
    def test_get_commit_id_from_ref_404(self):
        """
        Attempt to fetch a branch that has been deleted
        """
        responses.add(
            responses.GET,
            'https://api.github.com/repos/edx/edx-platform/git/refs/heads/deleted-branch',
            body=json.dumps({'message': 'Not Found'}),
            content_type='application/json; charset=utf8',
            status=404)

        with self.assertRaises(github.ObjectDoesNotExist):
            github.get_commit_id_from_ref('edx/edx-platform', 'deleted-branch')
Example #3
0
    def set_to_branch_tip(self, branch_name=None, ref_type=None, commit=True):
        """
        Set the `commit_id` to the current tip of the branch

        By default, save the instance object - pass `commit=False` to not save it
        """
        if branch_name is not None:
            self.branch_name = branch_name
        if ref_type is not None:
            self.ref_type = ref_type
        self.log('info', 'Setting instance {} to tip of branch {}'.format(self, self.branch_name))
        new_commit_id = github.get_commit_id_from_ref(
            self.fork_name,
            self.branch_name,
            ref_type=self.ref_type)

        if new_commit_id != self.commit_id:
            old_commit_short_id = self.commit_short_id
            self.commit_id = new_commit_id

            # Update the hash in the instance title if it is present there
            # TODO: Find a better way to handle this - include the hash dynamically?
            # TODO: Figure out why the warnings aren't suppressed despite the fact that it's a mixin
            if self.name and old_commit_short_id: #pylint: disable=access-member-before-definition
                #pylint: disable=attribute-defined-outside-init
                self.name = self.name.replace(old_commit_short_id, self.commit_short_id)

        if commit:
            self.save()
Example #4
0
    def set_to_branch_tip(self, branch_name=None, ref_type=None, commit=True):
        """
        Set the `commit_id` to the current tip of the branch

        By default, save the instance object - pass `commit=False` to not save it
        """
        if branch_name is not None:
            self.branch_name = branch_name
        if ref_type is not None:
            self.ref_type = ref_type
        self.logger.info('Setting instance to tip of branch %s', self.branch_name)
        try:
            new_commit_id = github.get_commit_id_from_ref(
                self.fork_name,
                self.branch_name,
                ref_type=self.ref_type)
        except github.ObjectDoesNotExist:
            self.logger.error("Branch '%s' not found. Has it been deleted on GitHub?",
                              self.branch_name)
            raise

        if new_commit_id != self.commit_id:
            old_commit_short_id = self.commit_short_id
            self.commit_id = new_commit_id

            # Update the hash in the instance title if it is present there
            # TODO: Find a better way to handle this - include the hash dynamically?
            if self.name and old_commit_short_id:
                #pylint: disable=attribute-defined-outside-init
                self.name = self.name.replace(old_commit_short_id, self.commit_short_id)

        if commit:
            self.save()
Example #5
0
 def test_get_commit_id_from_ref(self):
     """
     Obtaining `commit_id` from a repo reference (eg. a branch)
     """
     responses.add(
         responses.GET, 'https://api.github.com/repos/edx/edx-platform/git/refs/heads/master',
         body=json.dumps({'object': {'sha': 'test-sha'}}),
         content_type='application/json; charset=utf8',
         status=200)
     self.assertEqual(
         github.get_commit_id_from_ref('edx/edx-platform', 'master'),
         'test-sha')
Example #6
0
 def test_get_commit_id_from_ref(self):
     """
     Obtaining `commit_id` from a repo reference (eg. a branch)
     """
     responses.add(
         responses.GET,
         "https://api.github.com/repos/edx/edx-platform/git/refs/heads/master",
         body=json.dumps({"object": {"sha": "test-sha"}}),
         content_type="application/json; charset=utf8",
         status=200,
     )
     self.assertEqual(github.get_commit_id_from_ref("edx/edx-platform", "master"), "test-sha")
Example #7
0
 def test_get_commit_id_from_ref(self):
     """
     Obtaining `commit_id` from a repo reference (eg. a branch)
     """
     responses.add(
         responses.GET,
         'https://api.github.com/repos/edx/edx-platform/git/refs/heads/master',
         body=json.dumps({'object': {
             'sha': 'test-sha'
         }}),
         content_type='application/json; charset=utf8',
         status=200)
     self.assertEqual(
         github.get_commit_id_from_ref('edx/edx-platform', 'master'),
         'test-sha')