Esempio n. 1
0
def comment_pull_request(task_id):
    """Comment pull request on github"""
    task = Tasks.find_one(task_id)
    project = Project.objects.get(name=task['project'])
    if task.get('is_private'):
        if project.comment_from_owner_account:
            github = project.owner.github
        else:
            return
    else:
        github = Github(
            settings.GITHUB_COMMENTER_USER, settings.GITHUB_COMMENTER_PASSWORD,
        )
    repo = github.get_repo(project.name)
    pull_request = repo.get_pull(task['pull_request_id'])
    html_comment = render_to_string(
        'tasks/pull_request_comment.html', {
            'badge': project.get_badge_url(commit=task['commit']['hash']),
            'task': task,
            'url': make_https('/#/tasks/{}/'.format(task['_id'])),
        }
    )
    pull_request.create_issue_comment(
        html2text(html_comment)
    )
Esempio n. 2
0
 def get_badge_url(self, **kwargs):
     """Get or create https badge url"""
     if not self.badge_url:
         local_url = reverse('projects_badge', args=(self.name,))
         local_url += '?{}'.format('&'.join(
             '{}={}'.format(key, value) for key, value in kwargs.items(),
         ))
         self.badge_url = make_https(local_url)
         self.save()
     return self.badge_url
Esempio n. 3
0
def mark_commit_with_status(task_id):
    """Mark commit with status"""
    task = Tasks.find_one(task_id)
    project = Project.objects.get(name=task["project"])
    commit = project.repo.get_commit(task["commit"]["hash"])
    commit.create_status(
        const.GITHUB_STATES.get(task["status"], "error"),
        make_https("/#/tasks/{}/".format(task["_id"])),
        (const.GITHUB_DESCRIPTION_OK if task["status"] == const.STATUS_SUCCESS else const.GITHUB_DESCRIPTION_FAIL),
    )
Esempio n. 4
0
def mark_commit_with_status(task_id):
    """Mark commit with status"""
    task = Tasks.find_one(task_id)
    project = Project.objects.get(name=task['project'])
    commit = project.repo.get_commit(task['commit']['hash'])
    commit.create_status(
        const.GITHUB_STATES.get(task['status'], 'error'),
        make_https('/#/tasks/{}/'.format(task['_id'])),
        (const.GITHUB_DESCRIPTION_OK if task['status'] == const.STATUS_SUCCESS
         else const.GITHUB_DESCRIPTION_FAIL),
    )
Esempio n. 5
0
def mark_commit_with_status(task_id):
    """Mark commit with status"""
    task = Tasks.find_one(task_id)
    project = Project.objects.get(name=task['project'])
    commit = project.repo.get_commit(task['commit']['hash'])
    commit.create_status(
        const.GITHUB_STATES.get(task['status'], 'error'),
        make_https('/#/tasks/{}/'.format(task['_id'])),
        (
            const.GITHUB_DESCRIPTION_OK
            if task['status'] == const.STATUS_SUCCESS else
            const.GITHUB_DESCRIPTION_FAIL
        ),
    )
Esempio n. 6
0
def comment_pull_request(task_id):
    """Comment pull request on github"""
    task = Tasks.find_one(task_id)
    project = Project.objects.get(name=task["project"])
    if task.get("is_private"):
        if project.comment_from_owner_account:
            github = project.owner.github
        else:
            return
    else:
        github = Github(settings.GITHUB_COMMENTER_USER, settings.GITHUB_COMMENTER_PASSWORD)
    repo = github.get_repo(project.name)
    pull_request = repo.get_pull(task["pull_request_id"])
    html_comment = render_to_string(
        "tasks/pull_request_comment.html",
        {
            "badge": project.get_badge_url(commit=task["commit"]["hash"]),
            "task": task,
            "url": make_https("/#/tasks/{}/".format(task["_id"])),
        },
    )
    pull_request.create_issue_comment(html2text(html_comment))
Esempio n. 7
0
def comment_pull_request(task_id):
    """Comment pull request on github"""
    task = Tasks.find_one(task_id)
    project = Project.objects.get(name=task['project'])
    if task.get('is_private'):
        if project.comment_from_owner_account:
            github = project.owner.github
        else:
            return
    else:
        github = Github(
            settings.GITHUB_COMMENTER_USER,
            settings.GITHUB_COMMENTER_PASSWORD,
        )
    repo = github.get_repo(project.name)
    pull_request = repo.get_pull(task['pull_request_id'])
    html_comment = render_to_string(
        'tasks/pull_request_comment.html', {
            'badge': project.get_badge_url(commit=task['commit']['hash']),
            'task': task,
            'url': make_https('/#/tasks/{}/'.format(task['_id'])),
        })
    pull_request.create_issue_comment(html2text(html_comment))