Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API's to Fetch and Integrate the updated Projects and the Contributors #2464

Merged
merged 13 commits into from
Jul 23, 2024

Conversation

Uttkarsh-raj
Copy link
Contributor

PR Desc :

This PR is regarding the Projects and Contributors section. We currently don't have the feature to show the updated contributors list until it is updated in the json file, so the api's will help in doing so. This pr :

  • Provides a POST api to add a new project
    • the api also fetches the data like the logo and stores it locally for easy retrieval
    • Request :
       {
          "name": "BLT",
          "description": "OWASP BLT is a bug logging tool to report issues.",
          "github_url": "https://github.com/OWASP-BLT/BLT",
          "wiki_url": "",
          "homepage_url": "",
           "logo": null
      }
      
    • name , description and github_url are the required fields if the logo is not provided it fetches the owners logo
    • Response :
      {
             "id": 1,
             "name": "BLT",
             "slug": "blt",
             "description": "OWASP BLT is a bug logging tool to report issues",
             "github_url": "https://github.com/OWASP-BLT/BLT",
             "wiki_url": "",
             "homepage_url": "",
             "logo": "/media/project_logos/blt_YiVF2cg.png",
             "created": "2024-07-17T11:13:55.325994Z",
             "modified": "2024-07-18T08:06:55.216088Z",
             "contributors": [
             1622482,
             1622483
             ]
      }
      
    • the contributors are pulled from the GitHub repo using the github api and stored in the database.

  • Provides a GET api to get the data of the contributors and the project
    • Request :
       curl http://localhost:8000/api/v1/projects/
      
    • Response :
      {
      "count": 1,
      "projects": [
         {
             "id": 17,
             "name": "BLT",
             "slug": "blt",
             "description": "OWASP BLT is a bug logging tool to report issues ",
             "github_url": "https://github.com/OWASP-BLT/BLT",
             "wiki_url": "",
             "homepage_url": "",
             "logo": "/media/project_logos/blt_YiVF2cg.png",
             "created": "2024-07-17T11:13:55.325994Z",
             "modified": "2024-07-18T08:06:55.216088Z",
             "contributors": [
                 {
                     "id": 1622482,
                     "name": "A",
                     "github_id": 68425016,
                     "github_url": "https://github.com/A",
                     "avatar": "https://avatars.githubusercontent.com/u/asda344?v=24",
                     "contributor_type": "User",
                     "contributions": 10
                 },
                 {
                     "id": 1622483,
                     "name": "C",
                     "github_id": 16963976,
                     "github_url": "https://github.com/C",
                     "avatar": "https://avatars.githubusercontent.com/u/eq1231?v=4",
                     "contributor_type": "User",
                     "contributions": 1
                 },
              ]
           }
      

  • Provides a Patch api to update the contributors
    • the api fetches the data of the contributors from the github api's
    • Request :
      curl --request PATCH http://localhost:8000/api/v1/projects/
      
    • Response :
      {
             "id": 1,
             "name": "BLT",
             "slug": "blt",
             "description": "OWASP BLT is a bug logging tool to report issues",
             "github_url": "https://github.com/OWASP-BLT/BLT",
             "wiki_url": "",
             "homepage_url": "",
             "logo": "/media/project_logos/blt_YiVF2cg.png",
             "created": "2024-07-17T11:13:55.325994Z",
             "modified": "2024-07-18T08:06:55.216088Z",
             "contributors": [
             1622482,
             1622483,
             1534793,
             3482642,
             ]
      }
      

This pr addresses the following issues :

Demo :

Project.Django.REST.framework.-.Brave.2024-07-18.15-53-24.mp4

DonnieBLT
DonnieBLT previously approved these changes Jul 18, 2024
@Uttkarsh-raj
Copy link
Contributor Author

@arkid15r , @AtmegaBuzz any changes/optimizations you would recommend?

Copy link
Contributor

@arkid15r arkid15r left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, @Uttkarsh-raj !

@arkid15r , @AtmegaBuzz any changes/optimizations you would recommend?

Sure, here you can find something to start from if you'd like:

blt/urls.py Outdated Show resolved Hide resolved
website/api/views.py Outdated Show resolved Hide resolved
website/api/views.py Outdated Show resolved Hide resolved
website/api/views.py Outdated Show resolved Hide resolved
website/models.py Outdated Show resolved Hide resolved
website/models.py Outdated Show resolved Hide resolved
website/models.py Show resolved Hide resolved
Copy link
Contributor

@arkid15r arkid15r left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for updating the code, Uttkarsh!

website/models.py Show resolved Hide resolved
website/api/views.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@DonnieBLT DonnieBLT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm

@DonnieBLT DonnieBLT enabled auto-merge (squash) July 20, 2024 18:48
@DonnieBLT DonnieBLT merged commit dce2ccf into OWASP-BLT:main Jul 23, 2024
8 checks passed
Copy link

sentry-io bot commented Jul 23, 2024

Suspect Issues

This pull request was deployed and Sentry observed the following issues:

  • ‼️ ProgrammingError: relation "website_contributor" does not exist /api/v1/projects/ View Issue

Did you find this useful? React with a 👍 or 👎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants