Skip to content
This repository was archived by the owner on May 30, 2024. It is now read-only.

Commit b520817

Browse files
author
noah
committed
Fix the link
1 parent 7ab9345 commit b520817

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

internal/pkg/github/link.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ package github
22

33
import (
44
"context"
5+
"fmt"
56
"net/http"
6-
"path"
77

88
"github.com/gitploy-io/gitploy/model/ent"
99
"github.com/gitploy-io/gitploy/pkg/e"
@@ -23,7 +23,7 @@ func (g *Github) GetConfigRedirectURL(ctx context.Context, u *ent.User, r *ent.R
2323

2424
// The latest version file on the main branch.
2525
// https://docs.github.com/en/repositories/working-with-files/using-files/getting-permanent-links-to-files
26-
url := path.Join(*remote.HTMLURL, "blob", *remote.DefaultBranch, r.ConfigPath)
26+
url := fmt.Sprintf("%s/blob/%s/%s", *remote.HTMLURL, *remote.DefaultBranch, r.ConfigPath)
2727
return url, nil
2828
}
2929

@@ -41,6 +41,6 @@ func (g *Github) GetNewFileRedirectURL(ctx context.Context, u *ent.User, r *ent.
4141

4242
// Redirect to the URL to create a configuration file.
4343
// https://docs.github.com/en/[email protected]/repositories/working-with-files/managing-files/creating-new-files
44-
url := path.Join(*remote.HTMLURL, "new", *remote.DefaultBranch, r.ConfigPath)
44+
url := fmt.Sprintf("%s/new/%s/%s", *remote.HTMLURL, *remote.DefaultBranch, r.ConfigPath)
4545
return url, nil
4646
}

internal/server/web/link.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,18 @@ func (w *Web) RedirectToConfig(c *gin.Context) {
2525
r, err := w.i.FindRepoOfUserByNamespaceName(ctx, u, namespace, name)
2626
if err != nil {
2727
w.log.Check(gb.GetZapLogLevel(err), "Failed to get the repository.").Write(zap.Error(err))
28-
gb.AbortWithError(c, err)
28+
c.String(http.StatusForbidden, "It has failed to get the repository.")
2929
return
3030
}
3131

3232
url, err := w.i.GetConfigRedirectURL(ctx, u, r)
3333
if err != nil {
3434
w.log.Check(gb.GetZapLogLevel(err), "Failed to get the redirect URL for the configuration file.").Write(zap.Error(err))
35-
gb.AbortWithError(c, err)
35+
c.String(http.StatusInternalServerError, "It has failed to get the redirect URL for the configuration file.")
3636
return
3737
}
3838

39+
w.log.Debug("Redirect to the URL.", zap.String("URL", url))
3940
c.Redirect(http.StatusMovedPermanently, url)
4041
}
4142

@@ -54,16 +55,17 @@ func (w *Web) RedirectToNewConfig(c *gin.Context) {
5455
r, err := w.i.FindRepoOfUserByNamespaceName(ctx, u, namespace, name)
5556
if err != nil {
5657
w.log.Check(gb.GetZapLogLevel(err), "Failed to get the repository.").Write(zap.Error(err))
57-
gb.AbortWithError(c, err)
58+
c.String(http.StatusForbidden, "It has failed to get the repository.")
5859
return
5960
}
6061

6162
url, err := w.i.GetNewFileRedirectURL(ctx, u, r)
6263
if err != nil {
6364
w.log.Check(gb.GetZapLogLevel(err), "Failed to get the redirect URL to create a new file.").Write(zap.Error(err))
64-
gb.AbortWithError(c, err)
65+
c.String(http.StatusInternalServerError, "It has failed to get the redirect URL for the configuration file.")
6566
return
6667
}
6768

68-
c.Redirect(http.StatusMovedPermanently, url)
69+
w.log.Debug("Redirect to the URL.", zap.String("URL", url))
70+
c.Redirect(http.StatusFound, url)
6971
}

0 commit comments

Comments
 (0)