Пример #1
0
def handle_assign_to(
    integration: Integration,
    external_issue_key: str | None,
    assigned_to: Mapping[str, str] | None,
) -> None:
    if not assigned_to:
        return

    email: str | None = None
    assign = False

    new_value = assigned_to.get("newValue")
    if new_value is not None:
        email = parse_email(new_value)
        if not email:
            logger.info(
                "vsts.failed-to-parse-email-in-handle-assign-to",
                extra={
                    "error": "parse_error",
                    "integration_id": integration.id,
                    "assigned_to_values": assigned_to,
                    "external_issue_key": external_issue_key,
                },
            )
            return  # TODO(mgaeta): return if cannot parse email?
        assign = True

    sync_group_assignee_inbound(
        integration=integration,
        email=email,
        external_issue_key=external_issue_key,
        assign=assign,
    )
Пример #2
0
 def _format_commits(self, repo, commit_list):
     return [{
         "id": c["hash"],
         "repository": repo.name,
         "author_email": parse_email(c["author"]["raw"]),
         "author_name": parse_user_name(c["author"]["raw"]),
         "message": c["message"],
         "patch_set": c.get("patch_set"),
     } for c in commit_list]
Пример #3
0
    def __call__(self, organization, event):
        authors = {}

        try:
            repo = Repository.objects.get(
                organization_id=organization.id,
                provider=PROVIDER_NAME,
                external_id=str(event["repository"]["uuid"]),
            )
        except Repository.DoesNotExist:
            raise Http404()

        # while we're here, make sure repo data is up to date
        self.update_repo_data(repo, event)

        for change in event["push"]["changes"]:
            for commit in change.get("commits", []):
                if IntegrationRepositoryProvider.should_ignore_commit(
                        commit["message"]):
                    continue

                author_email = parse_email(commit["author"]["raw"])

                # TODO(dcramer): we need to deal with bad values here, but since
                # its optional, lets just throw it out for now
                if author_email is None or len(author_email) > 75:
                    author = None
                elif author_email not in authors:
                    authors[
                        author_email] = author = CommitAuthor.objects.get_or_create(
                            organization_id=organization.id,
                            email=author_email,
                            defaults={
                                "name":
                                commit["author"]["raw"].split("<")[0].strip()
                            },
                        )[0]
                else:
                    author = authors[author_email]
                try:
                    with transaction.atomic():

                        Commit.objects.create(
                            repository_id=repo.id,
                            organization_id=organization.id,
                            key=commit["hash"],
                            message=commit["message"],
                            author=author,
                            date_added=parse_date(commit["date"]).astimezone(
                                timezone.utc),
                        )

                except IntegrityError:
                    pass