Esempio n. 1
0
def reconcile_db_with_gh(*args, **kwargs):
    ghc = GitHubConnector()
    repos = ghc.get_all_repos()
    issues = ghc.get_all_issues()

    for repo in repos:
        r = Repo(github_id=repo.id, name=repo.name, url=repo.html_url)
        r.save()

    for issue in issues:
        i = Issue(github_id=issue.id)
        i.title = issue.title
        i.number = issue.number
        i.repo = Repo.objects.get(name=issue.repository[1])
        i.open = not issue.is_closed()
        i.url = issue.html_url
        if issue.assignee:
            try:
                i.assignee = GithubAlias.objects.get(github_name=issue.assignee).user
            except GithubAlias.DoesNotExist:
                print("No GithubAlias with github_name '%s' exists" % issue.assignee)
        else:
            i.assignee = None
        i.body = issue.body
        i.save()

    print("Not only did your task run successfully, but you're damned good looking too.")
Esempio n. 2
0
    def save(self, *args, **kwargs):
        if(not self.job.available_all_users):
            if(not self.job.users.filter(id=self.user.id).exists()):
                raise ValueError("Specified job is not available to {user}".format(user=str(self.user)))

        commit, sha, text = ['', '', '']

        text_string = self.text.split()

        if len(text_string) == 2:
            commit = text_string[0]
            sha = text_string[1]
        elif len(text_string) == 1:
            commit = text_string[0]
        else:
            commit, sha, text = self.text.split(None, 2)

        # If the text begins with "commit <sha1>", we'll sub in the actual commit message
        if (commit == "commit" and self.repo):

            ghc = GitHubConnector()
            repos = ghc.get_all_repos()

            for repo in repos:
                if repo.id == self.repo.github_id:
                    msg = repo.commit(sha).commit.message
                    self.text = '%s %s' % (msg, text)
                    break

        super(WorkItem, self).save(*args, **kwargs)
Esempio n. 3
0
    def setUp(self):
        self.ghc = GitHubConnector()
        self.repos = self.ghc.get_all_repos()

        for repo in self.repos:
            new_repo = Repo(github_id=repo.id, name=repo.name)
            new_repo.save()

        factories.UserFactory.create_batch(10)
        factories.JobFactory.create_batch(10)
Esempio n. 4
0
class WorkItemCommitHashSwapTestCase(TestCase):

    def setUp(self):
        self.ghc = GitHubConnector()
        self.repos = self.ghc.get_all_repos()

        for repo in self.repos:
            new_repo = Repo(github_id=repo.id, name=repo.name)
            new_repo.save()

        factories.UserFactory.create_batch(10)
        factories.JobFactory.create_batch(10)

    def test_commit_hash_swap(self):

        repo = self.repos.pop()
        commit = repo.iter_commits().next()

        repo_obj = Repo()
        repo_obj.github_id = repo.id
        repo_obj.name = repo.name
        repo_obj.save()

        workitem = WorkItem()
        workitem.user = User.objects.all()[0]
        workitem.job = Job.objects.filter(available_all_users=True)[0]
        workitem.hours = 10
        workitem.date = datetime.date.today()
        workitem.repo = repo_obj
        workitem.text = 'commit ' + commit.sha + ' extra text'
        workitem.save()

        self.assertEquals(workitem.text, commit.commit.message + ' extra text')

    def test_no_commit(self):

        for i in range(0, 30):

            repo = Repo.objects.all()[0]
            workitem = WorkItem()
            workitem.user = User.objects.all()[0]
            workitem.job = Job.objects.filter(available_all_users=True)[0]
            workitem.hours = 10
            workitem.date = datetime.date.today()
            workitem.repo = repo
            text = faker.sentence()
            workitem.text = text
            workitem.save()

            self.assertEquals(workitem.text, text)