Пример #1
0
    def __call__(self, organization, integration_id, event):
        authors = {}

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

        client = repo.get_provider().get_installation(
            integration_id, organization.id).get_client()

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

        [project_name, repo_name] = repo.name.split("/")

        for change in event["changes"]:
            from_hash = None if change.get(
                "fromHash") == "0" * 40 else change.get("fromHash")
            for commit in client.get_commits(project_name, repo_name,
                                             from_hash, change.get("toHash")):

                if IntegrationRepositoryProvider.should_ignore_commit(
                        commit["message"]):
                    continue

                author_email = commit["author"]["emailAddress"]

                # 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"]["name"]},
                        )[0]
                else:
                    author = authors[author_email]
                try:
                    with transaction.atomic():

                        Commit.objects.create(
                            repository_id=repo.id,
                            organization_id=organization.id,
                            key=commit["id"],
                            message=commit["message"],
                            author=author,
                            date_added=datetime.fromtimestamp(
                                commit["authorTimestamp"] / 1000,
                                timezone.utc),
                        )

                except IntegrityError:
                    pass
Пример #2
0
    def __call__(self, organization, event):
        authors = {}

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

        if repo.config.get("name") != event["repository"]["full_name"]:
            repo.config["name"] = event["repository"]["full_name"]
            repo.save()

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

                author_email = parse_raw_user_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=dateutil.parser.parse(
                                commit["date"]).astimezone(timezone.utc),
                        )

                except IntegrityError:
                    pass
Пример #3
0
    def __call__(self, organization, event):
        authors = {}

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

        if repo.config.get('name') != event['repository']['full_name']:
            repo.config['name'] = event['repository']['full_name']
            repo.save()

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

                author_email = parse_raw_user_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=dateutil.parser.parse(
                                commit['date'],
                            ).astimezone(timezone.utc),
                        )

                except IntegrityError:
                    pass
Пример #4
0
    def __call__(self, integration, organization, event):
        repo = self.get_repo(integration, organization, event)
        if repo is None:
            return

        # TODO(kmclb): turn this back on once tri-level repo problem has been solved
        # while we're here, make sure repo data is up to date
        # self.update_repo_data(repo, event)

        authors = {}

        # TODO gitlab only sends a max of 20 commits. If a push contains
        # more commits they provide a total count and require additional API
        # requests to fetch the commit details
        for commit in event.get("commits", []):
            if IntegrationRepositoryProvider.should_ignore_commit(
                    commit["message"]):
                continue

            author_email = commit["author"]["email"]

            # 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"]["name"]},
                    )[0]
            else:
                author = authors[author_email]
            try:
                with transaction.atomic():
                    Commit.objects.create(
                        repository_id=repo.id,
                        organization_id=organization.id,
                        key=commit["id"],
                        message=commit["message"],
                        author=author,
                        date_added=dateutil.parser.parse(
                            commit["timestamp"]).astimezone(timezone.utc),
                    )
            except IntegrityError:
                pass
Пример #5
0
    def __call__(self, integration, organization, event):
        repo = self.get_repo(integration, organization, event)
        if repo is None:
            return

        authors = {}

        # TODO gitlab only sends a max of 20 commits. If a push contains
        # more commits they provide a total count and require additional API
        # requests to fetch the commit details
        for commit in event.get('commits', []):
            if IntegrationRepositoryProvider.should_ignore_commit(
                    commit['message']):
                continue

            author_email = commit['author']['email']

            # 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']['name']})[0]
            else:
                author = authors[author_email]
            try:
                with transaction.atomic():
                    Commit.objects.create(
                        repository_id=repo.id,
                        organization_id=organization.id,
                        key=commit['id'],
                        message=commit['message'],
                        author=author,
                        date_added=dateutil.parser.parse(
                            commit['timestamp'], ).astimezone(timezone.utc),
                    )
            except IntegrityError:
                pass
Пример #6
0
    def __call__(self, integration, organization, event):
        repo = self.get_repo(integration, organization, event)
        if repo is None:
            return

        authors = {}

        # TODO gitlab only sends a max of 20 commits. If a push contains
        # more commits they provide a total count and require additional API
        # requests to fetch the commit details
        for commit in event.get('commits', []):
            if IntegrationRepositoryProvider.should_ignore_commit(commit['message']):
                continue

            author_email = commit['author']['email']

            # 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']['name']}
                )[0]
            else:
                author = authors[author_email]
            try:
                with transaction.atomic():
                    Commit.objects.create(
                        repository_id=repo.id,
                        organization_id=organization.id,
                        key=commit['id'],
                        message=commit['message'],
                        author=author,
                        date_added=dateutil.parser.parse(
                            commit['timestamp'],
                        ).astimezone(timezone.utc),
                    )
            except IntegrityError:
                pass