Example #1
0
def update_task(pull_request: PullRequest, task_id: str):
    task_url = asana_helpers.task_url_from_task_id(task_id)
    pr_url = pull_request.url()
    logger.info(f"Updating task {task_url} for pull request {pr_url}")

    fields = asana_helpers.extract_task_fields_from_pull_request(pull_request)

    # TODO: Should extract_task_fields_from_pull_request be broken into two
    # methods, one for fields and one for followers?
    update_task_fields = {
        k: v
        for k, v in fields.items() if k in ("assignee", "name", "html_notes",
                                            "completed", "custom_fields")
    }
    asana_client.update_task(task_id, update_task_fields)
    asana_client.add_followers(task_id, fields["followers"])
    maybe_complete_tasks_on_merge(pull_request)
Example #2
0
def _task_description_from_pull_request(pull_request: PullRequest) -> str:
    link_to_pr = _link(pull_request.url())
    github_author = pull_request.author()
    author = _asana_user_url_from_github_user_handle(github_author.login())
    if author is None:
        author = _asana_display_name_for_github_user(github_author)
    status_reason = _task_completion_from_pull_request(pull_request)
    status = "complete" if status_reason.is_complete else "incomplete"
    return _wrap_in_tag(
        "body"
    )(_wrap_in_tag("em")
      ("This is a one-way sync from GitHub to Asana. Do not edit this task or comment on it!"
       ) + f"\n\n\uD83D\uDD17 {link_to_pr}" + "\n✍️ " + author +
      _generate_assignee_description(pull_request.assignee()) +
      f"\n❗️Task is {status} because {status_reason.reason}" +
      _wrap_in_tag("strong")("\n\nDescription:\n") +
      _format_github_text_for_asana(pull_request.body()))