mirror of
https://github.com/multica-ai/multica.git
synced 2026-07-26 20:45:37 +02:00
feat(github): add GitHub App integration for PR-issue linking
- Add database migration for github_installation and issue_pull_request tables - Implement GitHub webhook handler with HMAC-SHA256 signature validation - Auto-link PRs to issues via branch name and PR title/body identifiers - Auto-transition issue status to "done" when linked PR is merged - Add GitHub App installation OAuth callback flow - Add REST APIs for listing installations and pull requests - Add PR status card component in issue detail sidebar - Add Integrations settings tab with Connect GitHub flow - Real-time PR status updates via WebSocket events
This commit is contained in:
393
server/pkg/db/generated/github.sql.go
Normal file
393
server/pkg/db/generated/github.sql.go
Normal file
@@ -0,0 +1,393 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: github.sql
|
||||
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const createGitHubInstallation = `-- name: CreateGitHubInstallation :one
|
||||
INSERT INTO github_installation (workspace_id, installation_id, account_login, account_type, app_id)
|
||||
VALUES ($1, $2, $3, $4, $5)
|
||||
ON CONFLICT (workspace_id, installation_id) DO UPDATE
|
||||
SET account_login = EXCLUDED.account_login,
|
||||
account_type = EXCLUDED.account_type,
|
||||
updated_at = now()
|
||||
RETURNING id, workspace_id, installation_id, account_login, account_type, app_id, created_at, updated_at
|
||||
`
|
||||
|
||||
type CreateGitHubInstallationParams struct {
|
||||
WorkspaceID pgtype.UUID `json:"workspace_id"`
|
||||
InstallationID int64 `json:"installation_id"`
|
||||
AccountLogin string `json:"account_login"`
|
||||
AccountType string `json:"account_type"`
|
||||
AppID int64 `json:"app_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateGitHubInstallation(ctx context.Context, arg CreateGitHubInstallationParams) (GithubInstallation, error) {
|
||||
row := q.db.QueryRow(ctx, createGitHubInstallation,
|
||||
arg.WorkspaceID,
|
||||
arg.InstallationID,
|
||||
arg.AccountLogin,
|
||||
arg.AccountType,
|
||||
arg.AppID,
|
||||
)
|
||||
var i GithubInstallation
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.WorkspaceID,
|
||||
&i.InstallationID,
|
||||
&i.AccountLogin,
|
||||
&i.AccountType,
|
||||
&i.AppID,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const deleteGitHubInstallation = `-- name: DeleteGitHubInstallation :exec
|
||||
DELETE FROM github_installation WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteGitHubInstallation(ctx context.Context, id pgtype.UUID) error {
|
||||
_, err := q.db.Exec(ctx, deleteGitHubInstallation, id)
|
||||
return err
|
||||
}
|
||||
|
||||
const deleteGitHubInstallationByInstallationID = `-- name: DeleteGitHubInstallationByInstallationID :exec
|
||||
DELETE FROM github_installation WHERE installation_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteGitHubInstallationByInstallationID(ctx context.Context, installationID int64) error {
|
||||
_, err := q.db.Exec(ctx, deleteGitHubInstallationByInstallationID, installationID)
|
||||
return err
|
||||
}
|
||||
|
||||
const deleteIssuePullRequest = `-- name: DeleteIssuePullRequest :exec
|
||||
DELETE FROM issue_pull_request WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteIssuePullRequest(ctx context.Context, id pgtype.UUID) error {
|
||||
_, err := q.db.Exec(ctx, deleteIssuePullRequest, id)
|
||||
return err
|
||||
}
|
||||
|
||||
const findIssueByIdentifierNumber = `-- name: FindIssueByIdentifierNumber :one
|
||||
SELECT id, workspace_id, title, description, status, priority, assignee_type, assignee_id, creator_type, creator_id, parent_issue_id, acceptance_criteria, context_refs, position, due_date, created_at, updated_at, number FROM issue
|
||||
WHERE workspace_id = $1 AND number = $2
|
||||
`
|
||||
|
||||
type FindIssueByIdentifierNumberParams struct {
|
||||
WorkspaceID pgtype.UUID `json:"workspace_id"`
|
||||
Number int32 `json:"number"`
|
||||
}
|
||||
|
||||
func (q *Queries) FindIssueByIdentifierNumber(ctx context.Context, arg FindIssueByIdentifierNumberParams) (Issue, error) {
|
||||
row := q.db.QueryRow(ctx, findIssueByIdentifierNumber, arg.WorkspaceID, arg.Number)
|
||||
var i Issue
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.WorkspaceID,
|
||||
&i.Title,
|
||||
&i.Description,
|
||||
&i.Status,
|
||||
&i.Priority,
|
||||
&i.AssigneeType,
|
||||
&i.AssigneeID,
|
||||
&i.CreatorType,
|
||||
&i.CreatorID,
|
||||
&i.ParentIssueID,
|
||||
&i.AcceptanceCriteria,
|
||||
&i.ContextRefs,
|
||||
&i.Position,
|
||||
&i.DueDate,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.Number,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const findIssuesByBranch = `-- name: FindIssuesByBranch :many
|
||||
SELECT i.id, i.workspace_id, i.title, i.description, i.status, i.priority, i.assignee_type, i.assignee_id, i.creator_type, i.creator_id, i.parent_issue_id, i.acceptance_criteria, i.context_refs, i.position, i.due_date, i.created_at, i.updated_at, i.number FROM issue i
|
||||
JOIN workspace w ON w.id = i.workspace_id
|
||||
JOIN github_installation gi ON gi.workspace_id = w.id
|
||||
WHERE gi.installation_id = $1
|
||||
AND i.status NOT IN ('done', 'cancelled')
|
||||
ORDER BY i.updated_at DESC
|
||||
`
|
||||
|
||||
func (q *Queries) FindIssuesByBranch(ctx context.Context, installationID int64) ([]Issue, error) {
|
||||
rows, err := q.db.Query(ctx, findIssuesByBranch, installationID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []Issue{}
|
||||
for rows.Next() {
|
||||
var i Issue
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.WorkspaceID,
|
||||
&i.Title,
|
||||
&i.Description,
|
||||
&i.Status,
|
||||
&i.Priority,
|
||||
&i.AssigneeType,
|
||||
&i.AssigneeID,
|
||||
&i.CreatorType,
|
||||
&i.CreatorID,
|
||||
&i.ParentIssueID,
|
||||
&i.AcceptanceCriteria,
|
||||
&i.ContextRefs,
|
||||
&i.Position,
|
||||
&i.DueDate,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.Number,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const getGitHubInstallation = `-- name: GetGitHubInstallation :one
|
||||
SELECT id, workspace_id, installation_id, account_login, account_type, app_id, created_at, updated_at FROM github_installation WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetGitHubInstallation(ctx context.Context, id pgtype.UUID) (GithubInstallation, error) {
|
||||
row := q.db.QueryRow(ctx, getGitHubInstallation, id)
|
||||
var i GithubInstallation
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.WorkspaceID,
|
||||
&i.InstallationID,
|
||||
&i.AccountLogin,
|
||||
&i.AccountType,
|
||||
&i.AppID,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getGitHubInstallationByInstallationID = `-- name: GetGitHubInstallationByInstallationID :one
|
||||
SELECT id, workspace_id, installation_id, account_login, account_type, app_id, created_at, updated_at FROM github_installation WHERE installation_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetGitHubInstallationByInstallationID(ctx context.Context, installationID int64) (GithubInstallation, error) {
|
||||
row := q.db.QueryRow(ctx, getGitHubInstallationByInstallationID, installationID)
|
||||
var i GithubInstallation
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.WorkspaceID,
|
||||
&i.InstallationID,
|
||||
&i.AccountLogin,
|
||||
&i.AccountType,
|
||||
&i.AppID,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const listGitHubInstallations = `-- name: ListGitHubInstallations :many
|
||||
SELECT id, workspace_id, installation_id, account_login, account_type, app_id, created_at, updated_at FROM github_installation WHERE workspace_id = $1 ORDER BY created_at DESC
|
||||
`
|
||||
|
||||
func (q *Queries) ListGitHubInstallations(ctx context.Context, workspaceID pgtype.UUID) ([]GithubInstallation, error) {
|
||||
rows, err := q.db.Query(ctx, listGitHubInstallations, workspaceID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []GithubInstallation{}
|
||||
for rows.Next() {
|
||||
var i GithubInstallation
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.WorkspaceID,
|
||||
&i.InstallationID,
|
||||
&i.AccountLogin,
|
||||
&i.AccountType,
|
||||
&i.AppID,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listPullRequestsByIssue = `-- name: ListPullRequestsByIssue :many
|
||||
SELECT id, issue_id, workspace_id, repo_owner, repo_name, pr_number, title, status, author, url, branch, created_at, updated_at FROM issue_pull_request WHERE issue_id = $1 ORDER BY created_at DESC
|
||||
`
|
||||
|
||||
func (q *Queries) ListPullRequestsByIssue(ctx context.Context, issueID pgtype.UUID) ([]IssuePullRequest, error) {
|
||||
rows, err := q.db.Query(ctx, listPullRequestsByIssue, issueID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []IssuePullRequest{}
|
||||
for rows.Next() {
|
||||
var i IssuePullRequest
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.IssueID,
|
||||
&i.WorkspaceID,
|
||||
&i.RepoOwner,
|
||||
&i.RepoName,
|
||||
&i.PrNumber,
|
||||
&i.Title,
|
||||
&i.Status,
|
||||
&i.Author,
|
||||
&i.Url,
|
||||
&i.Branch,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listPullRequestsByWorkspace = `-- name: ListPullRequestsByWorkspace :many
|
||||
SELECT id, issue_id, workspace_id, repo_owner, repo_name, pr_number, title, status, author, url, branch, created_at, updated_at FROM issue_pull_request WHERE workspace_id = $1 ORDER BY updated_at DESC
|
||||
`
|
||||
|
||||
func (q *Queries) ListPullRequestsByWorkspace(ctx context.Context, workspaceID pgtype.UUID) ([]IssuePullRequest, error) {
|
||||
rows, err := q.db.Query(ctx, listPullRequestsByWorkspace, workspaceID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []IssuePullRequest{}
|
||||
for rows.Next() {
|
||||
var i IssuePullRequest
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.IssueID,
|
||||
&i.WorkspaceID,
|
||||
&i.RepoOwner,
|
||||
&i.RepoName,
|
||||
&i.PrNumber,
|
||||
&i.Title,
|
||||
&i.Status,
|
||||
&i.Author,
|
||||
&i.Url,
|
||||
&i.Branch,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const updatePullRequestStatus = `-- name: UpdatePullRequestStatus :exec
|
||||
UPDATE issue_pull_request
|
||||
SET status = $1, updated_at = now()
|
||||
WHERE repo_owner = $2 AND repo_name = $3 AND pr_number = $4
|
||||
`
|
||||
|
||||
type UpdatePullRequestStatusParams struct {
|
||||
Status string `json:"status"`
|
||||
RepoOwner string `json:"repo_owner"`
|
||||
RepoName string `json:"repo_name"`
|
||||
PrNumber int32 `json:"pr_number"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdatePullRequestStatus(ctx context.Context, arg UpdatePullRequestStatusParams) error {
|
||||
_, err := q.db.Exec(ctx, updatePullRequestStatus,
|
||||
arg.Status,
|
||||
arg.RepoOwner,
|
||||
arg.RepoName,
|
||||
arg.PrNumber,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
const upsertIssuePullRequest = `-- name: UpsertIssuePullRequest :one
|
||||
INSERT INTO issue_pull_request (issue_id, workspace_id, repo_owner, repo_name, pr_number, title, status, author, url, branch)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
|
||||
ON CONFLICT (issue_id, repo_owner, repo_name, pr_number) DO UPDATE
|
||||
SET title = EXCLUDED.title,
|
||||
status = EXCLUDED.status,
|
||||
author = EXCLUDED.author,
|
||||
url = EXCLUDED.url,
|
||||
branch = EXCLUDED.branch,
|
||||
updated_at = now()
|
||||
RETURNING id, issue_id, workspace_id, repo_owner, repo_name, pr_number, title, status, author, url, branch, created_at, updated_at
|
||||
`
|
||||
|
||||
type UpsertIssuePullRequestParams struct {
|
||||
IssueID pgtype.UUID `json:"issue_id"`
|
||||
WorkspaceID pgtype.UUID `json:"workspace_id"`
|
||||
RepoOwner string `json:"repo_owner"`
|
||||
RepoName string `json:"repo_name"`
|
||||
PrNumber int32 `json:"pr_number"`
|
||||
Title string `json:"title"`
|
||||
Status string `json:"status"`
|
||||
Author string `json:"author"`
|
||||
Url string `json:"url"`
|
||||
Branch pgtype.Text `json:"branch"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpsertIssuePullRequest(ctx context.Context, arg UpsertIssuePullRequestParams) (IssuePullRequest, error) {
|
||||
row := q.db.QueryRow(ctx, upsertIssuePullRequest,
|
||||
arg.IssueID,
|
||||
arg.WorkspaceID,
|
||||
arg.RepoOwner,
|
||||
arg.RepoName,
|
||||
arg.PrNumber,
|
||||
arg.Title,
|
||||
arg.Status,
|
||||
arg.Author,
|
||||
arg.Url,
|
||||
arg.Branch,
|
||||
)
|
||||
var i IssuePullRequest
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.IssueID,
|
||||
&i.WorkspaceID,
|
||||
&i.RepoOwner,
|
||||
&i.RepoName,
|
||||
&i.PrNumber,
|
||||
&i.Title,
|
||||
&i.Status,
|
||||
&i.Author,
|
||||
&i.Url,
|
||||
&i.Branch,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
Reference in New Issue
Block a user