Browse Source

Reorder vars on webhook, add ssh url clone

webdeploy
pebles 2 years ago
parent
commit
7b1fcca3e4
Signed by: pebles
GPG Key ID: 4501C52A9268B49C
  1. 10
      gitea/gitea.go
  2. 17
      gitea/webhook.go
  3. 10
      server/gitea.go
  4. 6
      tmpl/gitea.html

10
gitea/gitea.go

@ -148,4 +148,14 @@ func (r *Repo) CreateWebhook() error {
return nil
}
// Get repo info
func (r *Repo) GetSSHURL() (string, error) {
createdRepo, err := r.client.GetRepo(r.user, r.repo)
// TODO: <nil> no vale pa na
if err != nil {
log.Printf("Error on getting info from new created Repo.")
return "", err
}
return createdRepo.SSHURL, nil
}

17
gitea/webhook.go

@ -9,17 +9,18 @@ import (
"strings"
)
func (g *Gitea) WebhookDeploy(user, repo, multiweb, keypriv, keypub string) error {
func (g *Gitea) WebhookDeploy(user, repo, keypriv, keypub, cloneurl, multiweb string) error {
type WebhookData struct {
USER string
REPO string
MULTIWEB string
PUB string
KEY string
SECRET string
USER string
REPO string
PUB string
KEY string
SECRET string
CLONESSHURL string
MULTIWEB string
}
keypriv = strings.Replace(keypriv, "\n", "|", -1) // key to oneline string, no breaks, '|' (pipe) is newline.
whData := WebhookData{user, repo, multiweb, keypub, keypriv, g.webhookSecret}
whData := WebhookData{user, repo, keypub, keypriv, g.webhookSecret, cloneurl, multiweb }
jsonData, err := json.Marshal(whData)
if err != nil && err.Error() != "<nil>" {
log.Printf("Error marshaling data for webhook.")

10
server/gitea.go

@ -142,9 +142,17 @@ func (s *server) giteaHandler(w http.ResponseWriter, r *http.Request) {
log.Printf("Web deploy module: Set %s", folder)
// get clone url from created repo to send it to deploy webhook
cloneurl, err := repo.GetSSHURL()
if err != nil {
log.Printf("Web deploy module: Error getting info for new repo: %v", err)
data.ExitStatus = "err_gitea_connection"
response.execute(data)
return
}
// WEB HOST TASKS - send keys and set folder option via webhook.
if err = s.gitea.WebhookDeploy(usergitea, reponame, data.ExitStatus, keypriv, keypub); err != nil {
if err = s.gitea.WebhookDeploy(usergitea, reponame, keypriv, keypub, cloneurl, data.ExitStatus); err != nil {
log.Printf("Web deploy module: Error, web host unreachable: %v", err)
if err := repo.Delete(); err != nil {
log.Printf("Web deploy module: Error deleting repository: %v", err)

6
tmpl/gitea.html

@ -2,8 +2,8 @@
{{template "header_close.html"}}
{{template "navbar.html" .}}
{{ $webURL := "https://sindominio.net" }}
{{ $giteaURL := "https://git.sindominio.net" }}
{{ $webURL := "https://lee.egelesta.net" }}
{{ $giteaURL := "https://git.papandr.eu" }}
{{ $repoButton := true }}
{{ $err_msg := "" }}
{{ $err_description := "" }}
@ -37,7 +37,7 @@
<div style="display: flex; justify-content: center;">
<button class="btn btn-primary" type="submit" class="btn btn-primary justify-content-center" style="width:80%;" name="mode" value="setfolder">Sólo desplegar web</button>
</div>
<p class="row justify-content-center" style="font-size:0.9em; margin-top:10px;"><i>No se creará/borrará el repositorio, sólo se desplegará la web en la opción seleccionada.</i><p>
<p class="row justify-content-center" style="font-size:0.9em; margin-top:10px;"><i>No se creará/borrará el repositorio, sólo se desplegará el repo web existente en la opción seleccionada.</i><p>
</form>
</div>

Loading…
Cancel
Save