Skip to content

Add GitHub product API settings#15303

Open
tungyhardDevOps wants to merge 2 commits into
DefectDojo:devfrom
tungyhardDevOps:fix/github-product-api
Open

Add GitHub product API settings#15303
tungyhardDevOps wants to merge 2 commits into
DefectDojo:devfrom
tungyhardDevOps:fix/github-product-api

Conversation

@tungyhardDevOps

Copy link
Copy Markdown

Description

Closes #8819.

This PR allows API clients to associate a GitHub project and an existing GitHub configuration while creating a product through POST /api/v2/products/.

The product serializer now accepts the optional, write-only github_project and github_configuration fields:

github_project = serializers.CharField(allow_blank=True, max_length=200, required=False, write_only=True)
github_configuration = serializers.PrimaryKeyRelatedField(
    allow_null=True,
    queryset=GITHUB_Conf.objects.all(),
    required=False,
    write_only=True,
)

After the product is created, the serializer creates the existing GITHUB_PKey relation when either GitHub field was supplied:

def create(self, validated_data):
    github_project = validated_data.pop("github_project", "")
    github_configuration = validated_data.pop("github_configuration", None)
    product = super().create(validated_data)
    if github_project or github_configuration:
        GITHUB_PKey.objects.create(
            product=product,
            git_project=github_project,
            git_conf=github_configuration,
        )
    return product

Test results

Added unittests/test_product_github_api.py covering:

  • Creating a product with a GitHub project and configuration.
  • Creating a product without GitHub settings.
  • Rejecting an unknown GitHub configuration without creating the product.

The focused Django tests passed:

Ran 3 tests in 8.803s

OK

Ruff 0.15.21 passed for both changed files. EXE002 was excluded locally because Docker Desktop marks Windows bind-mounted files as executable; Git records both files with normal 100644 modes.

All checks passed!

Documentation

Please update any documentation when needed in the documentation folder)

Checklist

This checklist is for your information.

  • Make sure to rebase your PR against the very latest dev.
  • Features/Changes should be submitted against the dev.
  • Bugfixes should be submitted against the bugfix branch.
  • Give a meaningful name to your PR, as it may end up being used in the release notes.
  • Your code is Ruff compliant (see ruff.toml).
  • Your code is python 3.13 compliant.
  • If this is a new feature and not a bug fix, you've included the proper documentation in the docs at https://github.com/DefectDojo/django-DefectDojo/tree/dev/docs as part of this PR.
  • Model changes must include the necessary migrations in the dojo/db_migrations folder.
  • Add applicable tests to the unit tests.
  • Add the proper label to categorize your PR.

@tungyhardDevOps

Copy link
Copy Markdown
Author

hello @Maffooch @blakeaowens could you please give this a review? thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant