blob: 2adc126607543c14b3712a19efb450bdd65c2dcc [file] [log] [blame]
iomodob23799d2025-07-31 14:08:22 +04001package api
2
3import (
4 "fmt"
5 "net/http"
6
7 "github.com/gin-gonic/gin"
8)
9
10func (apiObj *API) initProposal() {
11 apiObj.Proposal = apiObj.APIRoot.Group("/proposal")
12 apiObj.Proposal.POST("/approve", proposalApprovalHandler)
13}
14
15func proposalApprovalHandler(c *gin.Context) {
16 app, err := getApp(c)
17 if err != nil {
18 responseFormat(c, http.StatusInternalServerError, err.Error())
19 return
20 }
21
22 // Read the raw body for signature validation
23 body, err := c.GetRawData()
24 if err != nil {
25 responseFormat(c, http.StatusBadRequest, "Failed to read request body")
26 return
27 }
28
29 // Get the signature from headers
30 signature := c.GetHeader("X-Hub-Signature-256")
31 if signature == "" {
32 // Fallback to the older signature header
33 signature = c.GetHeader("X-Hub-Signature")
34 }
35
36 err = app.ProposalApproval(body, signature)
37 if err != nil {
38 responseFormat(c, http.StatusBadRequest, fmt.Sprintf("Failed to process webhook: %v", err))
39 return
40 }
41
42 responseFormat(c, http.StatusOK, "Proposal approved successfully")
43}