Real-Dev-Squad / website-backend

The backend code for all our website-related apps
https://api.realdevsquad.com/
MIT License
50 stars 220 forks source link

[RFC]: Store Org's all Pull Requests in Real Dev Squad Backend Database and Webhook Integration #1133

Open sahsisunny opened 1 year ago

sahsisunny commented 1 year ago

[RFC]: Store Org's all Pull Requests in Real Dev Squad Backend Database and Webhook Integration

Feature Name: Store Org's all Pull Requests in Real Dev Squad Backend Database and Webhook Integration

Summary

This RFC proposes a solution to store all pull requests from the Real Dev Squad organization in the Real Dev Squad backend database. It also suggests integrating a webhook to receive real-time updates from GitHub and keep the backend database synchronized.

Motivation

The purpose of this RFC is to outline a solution for storing Real Dev Squad's GitHub pull requests in the Real Dev Squad backend database. By integrating a webhook, the backend database can be updated in real-time, ensuring data consistency and providing a streamlined workflow.

Detailed design

1. Introduction

This RFC proposes storing the GitHub pull requests of the Real Dev Squad organization in the Real Dev Squad backend database. It also suggests using a webhook to retrieve the latest data from GitHub and keep the backend database updated in real-time.

2. Background

Real Dev Squad uses GitHub for source code management and collaboration. The Real Dev Squad backend database serves as a central repository for various organization data. To streamline workflows and maintain data consistency, it is essential to synchronize pull request information from GitHub into the backend database.

3. Objectives

The objectives of this RFC are as follows:

4. Proposed Solution

4.1. Database Schema

Design an appropriate database schema to store pull request data in the backend database. The schema should include fields such as pull request ID, title, description, author, creation timestamp, last update timestamp, status (open/closed), and other relevant information.

4.2. API Endpoint

Create an API endpoint in the Real Dev Squad backend to handle incoming requests for storing pull request data. The endpoint should process received data and persist it in the backend database.

4.3. Webhook Integration

Integrate a webhook mechanism with GitHub to receive event notifications related to pull requests. Configure the webhook to send notifications to the designated endpoint in the backend whenever a pull request is created, updated, or closed.

4.4. Event Processing

Upon receiving a webhook notification, the backend should authenticate the request, extract relevant data associated with the pull request, and process it. The processed data should be stored or used to update the corresponding record in the backend database.

4.5. Error Handling

Implement appropriate error handling mechanisms to address cases where webhook notifications fail to be processed or stored in the backend database. This may include logging, error notifications, and retry mechanisms to maintain data consistency.

5. Security Considerations

Ensure the API endpoint and webhook integration are secured using appropriate authentication mechanisms (e.g., OAuth or API keys) to prevent unauthorized access and data tampering.

6. Future Enhancements

In the future, consider additional features to enhance the pull request integration, such as implementing a two-way synchronization to update pull request status in GitHub when modified in the backend database.

Drawbacks

Drawbacks of the proposed design are:

Unresolved questions

Conclusion

This RFC proposes storing Real Dev Squad's GitHub pull requests in the Real Dev Squad backend database through webhook integration. The solution allows for real-time updates and ensures data consistency. Additional configuration and maintenance efforts may be required for the webhook integration and API endpoint. Security measures must be implemented to protect against unauthorized access and data tampering. Alternatives considered include periodic data storage using scheduled jobs, which do not provide real-time updates.

sahsisunny commented 1 year ago
[
  {
    "url": "https://api.github.com/repos/Real-Dev-Squad/website-status/pulls/576",
    "id": 1358171923,
    "node_id": "PR_kwDOEQJXR85Q9A8T",
    "html_url": "https://github.com/Real-Dev-Squad/website-status/pull/576",
    "diff_url": "https://github.com/Real-Dev-Squad/website-status/pull/576.diff",
    "patch_url": "https://github.com/Real-Dev-Squad/website-status/pull/576.patch",
    "issue_url": "https://api.github.com/repos/Real-Dev-Squad/website-status/issues/576",
    "number": 576,
    "state": "closed",
    "locked": false,
    "title": "Create pull_request_template.md",
    "user": {
      "login": "bhtibrewal",
      "id": 42600164,
      "node_id": "MDQ6VXNlcjQyNjAwMTY0",
      "avatar_url": "https://avatars.githubusercontent.com/u/42600164?v=4",
      "gravatar_id": "",
      "url": "https://api.github.com/users/bhtibrewal",
      "html_url": "https://github.com/bhtibrewal",
      "followers_url": "https://api.github.com/users/bhtibrewal/followers",
      "following_url": "https://api.github.com/users/bhtibrewal/following{/other_user}",
      "gists_url": "https://api.github.com/users/bhtibrewal/gists{/gist_id}",
      "starred_url": "https://api.github.com/users/bhtibrewal/starred{/owner}{/repo}",
      "subscriptions_url": "https://api.github.com/users/bhtibrewal/subscriptions",
      "organizations_url": "https://api.github.com/users/bhtibrewal/orgs",
      "repos_url": "https://api.github.com/users/bhtibrewal/repos",
      "events_url": "https://api.github.com/users/bhtibrewal/events{/privacy}",
      "received_events_url": "https://api.github.com/users/bhtibrewal/received_events",
      "type": "User",
      "site_admin": false
    },
    "body": "Issue: #577\r\nadded a template to standardize PRs",
    "created_at": "2023-05-21T10:13:57Z",
    "updated_at": "2023-05-25T16:44:26Z",
    "closed_at": "2023-05-25T16:44:25Z",
    "merged_at": "2023-05-25T16:44:25Z",
    "merge_commit_sha": "4dad25f6558e00cccb12e140b2bb70620095f890",
    "assignee": {
      // Same as user
    },
    "assignees": [
      // Same as user but in array
    ],
    "requested_reviewers": [],
    "requested_teams": [],
    "labels": [],
    "milestone": null,
    "draft": false,
    "commits_url": "https://api.github.com/repos/Real-Dev-Squad/website-status/pulls/576/commits",
    "review_comments_url": "https://api.github.com/repos/Real-Dev-Squad/website-status/pulls/576/comments",
    "review_comment_url": "https://api.github.com/repos/Real-Dev-Squad/website-status/pulls/comments{/number}",
    "comments_url": "https://api.github.com/repos/Real-Dev-Squad/website-status/issues/576/comments",
    "statuses_url": "https://api.github.com/repos/Real-Dev-Squad/website-status/statuses/087cf71ba3b38237a3e5217a9ab3816a871f3849",
    "head": {
      "label": "Real-Dev-Squad:make-pull_request_template",
      "ref": "make-pull_request_template",
      "sha": "087cf71ba3b38237a3e5217a9ab3816a871f3849",
      "user": {
        // Same as user
      },
      "repo": {
        "id": 285366087,
        "node_id": "MDEwOlJlcG9zaXRvcnkyODUzNjYwODc=",
        "name": "website-status",
        "full_name": "Real-Dev-Squad/website-status",
        "private": false,
        "owner": {
          // Same as user
        },
        "html_url": "https://github.com/Real-Dev-Squad/website-status",
        "description": "Shows a roadmap of the ongoing projects being done",
        "fork": false,
        "url": "https://api.github.com/repos/Real-Dev-Squad/website-status",
        "forks_url": "https://api.github.com/repos/Real-Dev-Squad/website-status/forks",
        "keys_url": "https://api.github.com/repos/Real-Dev-Squad/website-status/keys{/key_id}",
        "collaborators_url": "https://api.github.com/repos/Real-Dev-Squad/website-status/collaborators{/collaborator}",
        "teams_url": "https://api.github.com/repos/Real-Dev-Squad/website-status/teams",
        "hooks_url": "https://api.github.com/repos/Real-Dev-Squad/website-status/hooks",
        "issue_events_url": "https://api.github.com/repos/Real-Dev-Squad/website-status/issues/events{/number}",
        "events_url": "https://api.github.com/repos/Real-Dev-Squad/website-status/events",
        "assignees_url": "https://api.github.com/repos/Real-Dev-Squad/website-status/assignees{/user}",
        "branches_url": "https://api.github.com/repos/Real-Dev-Squad/website-status/branches{/branch}",
        "tags_url": "https://api.github.com/repos/Real-Dev-Squad/website-status/tags",
        "blobs_url": "https://api.github.com/repos/Real-Dev-Squad/website-status/git/blobs{/sha}",
        "git_tags_url": "https://api.github.com/repos/Real-Dev-Squad/website-status/git/tags{/sha}",
        "git_refs_url": "https://api.github.com/repos/Real-Dev-Squad/website-status/git/refs{/sha}",
        "trees_url": "https://api.github.com/repos/Real-Dev-Squad/website-status/git/trees{/sha}",
        "statuses_url": "https://api.github.com/repos/Real-Dev-Squad/website-status/statuses/{sha}",
        "languages_url": "https://api.github.com/repos/Real-Dev-Squad/website-status/languages",
        "stargazers_url": "https://api.github.com/repos/Real-Dev-Squad/website-status/stargazers",
        "contributors_url": "https://api.github.com/repos/Real-Dev-Squad/website-status/contributors",
        "subscribers_url": "https://api.github.com/repos/Real-Dev-Squad/website-status/subscribers",
        "subscription_url": "https://api.github.com/repos/Real-Dev-Squad/website-status/subscription",
        "commits_url": "https://api.github.com/repos/Real-Dev-Squad/website-status/commits{/sha}",
        "git_commits_url": "https://api.github.com/repos/Real-Dev-Squad/website-status/git/commits{/sha}",
        "comments_url": "https://api.github.com/repos/Real-Dev-Squad/website-status/comments{/number}",
        "issue_comment_url": "https://api.github.com/repos/Real-Dev-Squad/website-status/issues/comments{/number}",
        "contents_url": "https://api.github.com/repos/Real-Dev-Squad/website-status/contents/{+path}",
        "compare_url": "https://api.github.com/repos/Real-Dev-Squad/website-status/compare/{base}...{head}",
        "merges_url": "https://api.github.com/repos/Real-Dev-Squad/website-status/merges",
        "archive_url": "https://api.github.com/repos/Real-Dev-Squad/website-status/{archive_format}{/ref}",
        "downloads_url": "https://api.github.com/repos/Real-Dev-Squad/website-status/downloads",
        "issues_url": "https://api.github.com/repos/Real-Dev-Squad/website-status/issues{/number}",
        "pulls_url": "https://api.github.com/repos/Real-Dev-Squad/website-status/pulls{/number}",
        "milestones_url": "https://api.github.com/repos/Real-Dev-Squad/website-status/milestones{/number}",
        "notifications_url": "https://api.github.com/repos/Real-Dev-Squad/website-status/notifications{?since,all,participating}",
        "labels_url": "https://api.github.com/repos/Real-Dev-Squad/website-status/labels{/name}",
        "releases_url": "https://api.github.com/repos/Real-Dev-Squad/website-status/releases{/id}",
        "deployments_url": "https://api.github.com/repos/Real-Dev-Squad/website-status/deployments",
        "created_at": "2020-08-05T17:58:40Z",
        "updated_at": "2023-05-08T10:34:54Z",
        "pushed_at": "2023-05-25T17:21:30Z",
        "git_url": "git://github.com/Real-Dev-Squad/website-status.git",
        "ssh_url": "git@github.com:Real-Dev-Squad/website-status.git",
        "clone_url": "https://github.com/Real-Dev-Squad/website-status.git",
        "svn_url": "https://github.com/Real-Dev-Squad/website-status",
        "homepage": "https://status.realdevsquad.com/",
        "size": 5138,
        "stargazers_count": 15,
        "watchers_count": 15,
        "language": "TypeScript",
        "has_issues": true,
        "has_projects": true,
        "has_downloads": true,
        "has_wiki": true,
        "has_pages": false,
        "has_discussions": false,
        "forks_count": 108,
        "mirror_url": null,
        "archived": false,
        "disabled": false,
        "open_issues_count": 137,
        "license": {
          "key": "mit",
          "name": "MIT License",
          "spdx_id": "MIT",
          "url": "https://api.github.com/licenses/mit",
          "node_id": "MDc6TGljZW5zZTEz"
        },
        "allow_forking": true,
        "is_template": false,
        "web_commit_signoff_required": false,
        "topics": ["hacktoberfest", "react", "typescript"],
        "visibility": "public",
        "forks": 108,
        "open_issues": 137,
        "watchers": 15,
        "default_branch": "develop"
      }
    },
    "base": {
      // Same as above head object
    },
    "_links": {
      "self": {
        "href": "https://api.github.com/repos/Real-Dev-Squad/website-status/pulls/576"
      },
      "html": {
        "href": "https://github.com/Real-Dev-Squad/website-status/pull/576"
      },
      "issue": {
        "href": "https://api.github.com/repos/Real-Dev-Squad/website-status/issues/576"
      },
      "comments": {
        "href": "https://api.github.com/repos/Real-Dev-Squad/website-status/issues/576/comments"
      },
      "review_comments": {
        "href": "https://api.github.com/repos/Real-Dev-Squad/website-status/pulls/576/comments"
      },
      "review_comment": {
        "href": "https://api.github.com/repos/Real-Dev-Squad/website-status/pulls/comments{/number}"
      },
      "commits": {
        "href": "https://api.github.com/repos/Real-Dev-Squad/website-status/pulls/576/commits"
      },
      "statuses": {
        "href": "https://api.github.com/repos/Real-Dev-Squad/website-status/statuses/087cf71ba3b38237a3e5217a9ab3816a871f3849"
      }
    },
    "author_association": "CONTRIBUTOR",
    "auto_merge": null,
    "active_lock_reason": null
  }
]

Field which are required in the PR

PR user

Continue to PR

PR Assignee

Same as PR user

PR Assignees - Array

Same as PR Assignee but in array

Continue to PR

PR Head

PR Head User

Same as PR user

PR Head Repo

PR Head Repo Owner

Same as PR user and PR head user

Continue to PR Head Repo

PR Head Repo Owner License

Continue to PR Head Repo

PR base

Same as PR head

PR _links

Continue to PR

RitikJaiswal75 commented 1 year ago

Please mention the reason why we want to move all the pr data to rds

remember once @harshith-venkatesh told us that we can set up rules for naming PRs and based on that we can filter it out.