Api: publish api
This commit is contained in:
parent
b1df581f63
commit
2b18269af9
1 changed files with 21 additions and 0 deletions
21
main.go
21
main.go
|
@ -2,6 +2,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -187,6 +188,21 @@ func notify(jsonResponse string) {
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TriggerPublish() {
|
||||||
|
godotenv.Load(".botenv")
|
||||||
|
FORGEJO := os.Getenv("FORGEJO_TOKEN")
|
||||||
|
payload := `{"ref": "main"}`
|
||||||
|
apiURL := "https://git.askar.tv/api/v1/repos/nomad/alaskartv-app/actions/workflows/publish.yml/dispatches"
|
||||||
|
apiToken := FORGEJO
|
||||||
|
|
||||||
|
req, _ := http.NewRequest("POST", apiURL, bytes.NewBuffer([]byte(payload)))
|
||||||
|
req.Header.Set("Authorization", "token "+apiToken)
|
||||||
|
req.Header.Set("Content-Type", "application/json")
|
||||||
|
|
||||||
|
client := &http.Client{}
|
||||||
|
client.Do(req)
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
router := gin.Default()
|
router := gin.Default()
|
||||||
router.Use(cors.New(cors.Config{
|
router.Use(cors.New(cors.Config{
|
||||||
|
@ -238,6 +254,11 @@ func main() {
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
router.POST("/api/publish", func(c *gin.Context) {
|
||||||
|
TriggerPublish()
|
||||||
|
c.JSON(http.StatusOK, gin.H{"message": "Workflow triggered successfully"})
|
||||||
|
})
|
||||||
|
|
||||||
router.POST("/notify", notifyHandler)
|
router.POST("/notify", notifyHandler)
|
||||||
router.GET("/", func(c *gin.Context) {
|
router.GET("/", func(c *gin.Context) {
|
||||||
c.File("index.html")
|
c.File("index.html")
|
||||||
|
|
Loading…
Reference in a new issue