Skip to content

Commit

Permalink
Merge branch 'main' into docker-cli
Browse files Browse the repository at this point in the history
  • Loading branch information
anbraten committed Jun 10, 2024
2 parents 005a70b + 1953a0e commit db6e54a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 31 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
code.gitea.io/sdk/gitea v0.18.0
codeberg.org/6543/go-yaml2json v1.0.0
codeberg.org/6543/xyaml v1.1.0
codeberg.org/mvdkleijn/forgejo-sdk/forgejo v0.0.0-20240503154913-d2f7239d0250
codeberg.org/mvdkleijn/forgejo-sdk/forgejo v0.0.0-20240607215151-168c988b82c1
github.com/6543/logfile-open v1.2.1
github.com/adrg/xdg v0.4.0
github.com/alessio/shellescape v1.4.2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ codeberg.org/6543/go-yaml2json v1.0.0 h1:heGqo9VEi7gY2yNqjj7X4ADs5nzlFIbGsJtgYDL
codeberg.org/6543/go-yaml2json v1.0.0/go.mod h1:mz61q14LWF4ZABrgMEDMmk3t9dPi6zgR1uBh2VKV2RQ=
codeberg.org/6543/xyaml v1.1.0 h1:0PWTy8OUqshshjrrnAXFWXSPUEa8R49DIh2ah07SxFc=
codeberg.org/6543/xyaml v1.1.0/go.mod h1:jI7afXLZUxeL4rNNsG1SlHh78L+gma9lK1bIebyFZwA=
codeberg.org/mvdkleijn/forgejo-sdk/forgejo v0.0.0-20240503154913-d2f7239d0250 h1:VyMtcK3K2ltTQlpMPFueqcnt0NOyU8RSaEwUuCIoYoM=
codeberg.org/mvdkleijn/forgejo-sdk/forgejo v0.0.0-20240503154913-d2f7239d0250/go.mod h1:09wAYX9H0+wBo1baX9DdSqdfreZc6ji5aELsnu9m14M=
codeberg.org/mvdkleijn/forgejo-sdk/forgejo v0.0.0-20240607215151-168c988b82c1 h1:fwiekuoe+B8uz+Jpk0URaIOfklb2MWM8Pe0lNQck32A=
codeberg.org/mvdkleijn/forgejo-sdk/forgejo v0.0.0-20240607215151-168c988b82c1/go.mod h1:09wAYX9H0+wBo1baX9DdSqdfreZc6ji5aELsnu9m14M=
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a h1:lSA0F4e9A2NcQSqGqTOXqu2aRi/XEQxDCBwM8yJtE6s=
Expand Down
51 changes: 26 additions & 25 deletions server/api/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,23 +117,6 @@ func PostRepo(c *gin.Context) {
)
}

// creates the jwt token used to verify the repository
t := token.New(token.HookToken)
t.Set("repo-id", strconv.FormatInt(repo.ID, 10))
sig, err := t.Sign(repo.Hash)
if err != nil {
msg := "could not generate new jwt token."
log.Error().Err(err).Msg(msg)
c.String(http.StatusInternalServerError, msg)
return
}

hookURL := fmt.Sprintf(
"%s/api/hook?access_token=%s",
server.Config.Server.WebhookHost,
sig,
)

// find org of repo
var org *model.Org
org, err = _store.OrgFindByName(repo.Owner)
Expand Down Expand Up @@ -164,14 +147,6 @@ func PostRepo(c *gin.Context) {

repo.OrgID = org.ID

err = _forge.Activate(c, user, repo, hookURL)
if err != nil {
msg := "could not create webhook in forge."
log.Error().Err(err).Msg(msg)
c.String(http.StatusInternalServerError, msg)
return
}

if enabledOnce {
err = _store.UpdateRepo(repo)
} else {
Expand All @@ -184,6 +159,32 @@ func PostRepo(c *gin.Context) {
c.String(http.StatusInternalServerError, msg)
return
}

// creates the jwt token used to verify the repository
t := token.New(token.HookToken)
t.Set("repo-id", strconv.FormatInt(repo.ID, 10))
sig, err := t.Sign(repo.Hash)
if err != nil {
msg := "could not generate new jwt token."
log.Error().Err(err).Msg(msg)
c.String(http.StatusInternalServerError, msg)
return
}

hookURL := fmt.Sprintf(
"%s/api/hook?access_token=%s",
server.Config.Server.WebhookHost,
sig,
)

err = _forge.Activate(c, user, repo, hookURL)
if err != nil {
msg := "could not create webhook in forge."
log.Error().Err(err).Msg(msg)
c.String(http.StatusInternalServerError, msg)
return
}

repo.Perm = from.Perm
repo.Perm.Synced = time.Now().Unix()
repo.Perm.UserID = user.ID
Expand Down
6 changes: 3 additions & 3 deletions web/src/lib/api/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default class ApiClient {
this.csrf = csrf;
}

private async _request(method: string, path: string, data: unknown): Promise<unknown> {
private async _request(method: string, path: string, data?: unknown): Promise<unknown> {
const res = await fetch(`${this.server}${path}`, {
method,
headers: {
Expand Down Expand Up @@ -71,7 +71,7 @@ export default class ApiClient {
}

_get(path: string) {
return this._request('GET', path, null);
return this._request('GET', path);
}

_post(path: string, data?: unknown) {
Expand All @@ -83,7 +83,7 @@ export default class ApiClient {
}

_delete(path: string) {
return this._request('DELETE', path, null);
return this._request('DELETE', path);
}

_subscribe<T>(path: string, callback: (data: T) => void, opts = { reconnect: true }) {
Expand Down

0 comments on commit db6e54a

Please sign in to comment.