Skip to content

Commit 65a2d9e

Browse files
committed
Merge branch 'main' into css-fine-tue
2 parents 03f301b + 61d08f4 commit 65a2d9e

File tree

11 files changed

+288
-6
lines changed

11 files changed

+288
-6
lines changed

modules/context/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ func RepoRefForAPI(next http.Handler) http.Handler {
337337
if git.IsErrNotExist(err) {
338338
ctx.NotFound()
339339
} else {
340-
ctx.Error(http.StatusInternalServerError, "GetBlobByPath", err)
340+
ctx.Error(http.StatusInternalServerError, "GetCommit", err)
341341
}
342342
return
343343
}

modules/structs/miscellaneous.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,22 @@ type ServerVersion struct {
7272
Version string `json:"version"`
7373
}
7474

75+
// LicensesListEntry is used for the API
76+
type LicensesTemplateListEntry struct {
77+
Key string `json:"key"`
78+
Name string `json:"name"`
79+
URL string `json:"url"`
80+
}
81+
82+
// LicensesInfo contains information about a License
83+
type LicenseTemplateInfo struct {
84+
Key string `json:"key"`
85+
Name string `json:"name"`
86+
URL string `json:"url"`
87+
Implementation string `json:"implementation"`
88+
Body string `json:"body"`
89+
}
90+
7591
// APIError is an api error with a message
7692
type APIError struct {
7793
Message string `json:"message"`

modules/templates/helper.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,6 @@ func NewFuncMap() []template.FuncMap {
141141
"TimeSinceUnix": timeutil.TimeSinceUnix,
142142
"DateTime": timeutil.DateTime,
143143
"Sec2Time": util.SecToTime,
144-
"DateFmtLong": func(t time.Time) string {
145-
return t.Format(time.RFC3339)
146-
},
147144
"LoadTimes": func(startTime time.Time) string {
148145
return fmt.Sprint(time.Since(startTime).Nanoseconds()/1e6) + "ms"
149146
},

routers/api/v1/api.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,8 @@ func Routes(ctx gocontext.Context) *web.Route {
719719
m.Post("/markup", bind(api.MarkupOption{}), misc.Markup)
720720
m.Post("/markdown", bind(api.MarkdownOption{}), misc.Markdown)
721721
m.Post("/markdown/raw", misc.MarkdownRaw)
722+
m.Get("/licenses", misc.ListLicenseTemplates)
723+
m.Get("/licenses/{name}", misc.GetLicenseTemplateInfo)
722724
m.Group("/settings", func() {
723725
m.Get("/ui", settings.GetGeneralUISettings)
724726
m.Get("/api", settings.GetGeneralAPISettings)

routers/api/v1/misc/licenses.go

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// Copyright 2023 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package misc
5+
6+
import (
7+
"fmt"
8+
"net/http"
9+
"net/url"
10+
11+
"code.gitea.io/gitea/modules/context"
12+
"code.gitea.io/gitea/modules/options"
13+
repo_module "code.gitea.io/gitea/modules/repository"
14+
"code.gitea.io/gitea/modules/setting"
15+
api "code.gitea.io/gitea/modules/structs"
16+
"code.gitea.io/gitea/modules/util"
17+
)
18+
19+
// Returns a list of all License templates
20+
func ListLicenseTemplates(ctx *context.APIContext) {
21+
// swagger:operation GET /licenses miscellaneous listLicenseTemplates
22+
// ---
23+
// summary: Returns a list of all license templates
24+
// produces:
25+
// - application/json
26+
// responses:
27+
// "200":
28+
// "$ref": "#/responses/LicenseTemplateList"
29+
response := make([]api.LicensesTemplateListEntry, len(repo_module.Licenses))
30+
for i, license := range repo_module.Licenses {
31+
response[i] = api.LicensesTemplateListEntry{
32+
Key: license,
33+
Name: license,
34+
URL: fmt.Sprintf("%sapi/v1/licenses/%s", setting.AppURL, url.PathEscape(license)),
35+
}
36+
}
37+
ctx.JSON(http.StatusOK, response)
38+
}
39+
40+
// Returns information about a gitignore template
41+
func GetLicenseTemplateInfo(ctx *context.APIContext) {
42+
// swagger:operation GET /licenses/{name} miscellaneous getLicenseTemplateInfo
43+
// ---
44+
// summary: Returns information about a license template
45+
// produces:
46+
// - application/json
47+
// parameters:
48+
// - name: name
49+
// in: path
50+
// description: name of the license
51+
// type: string
52+
// required: true
53+
// responses:
54+
// "200":
55+
// "$ref": "#/responses/LicenseTemplateInfo"
56+
// "404":
57+
// "$ref": "#/responses/notFound"
58+
name := util.PathJoinRelX(ctx.Params("name"))
59+
60+
text, err := options.License(name)
61+
if err != nil {
62+
ctx.NotFound()
63+
return
64+
}
65+
66+
response := api.LicenseTemplateInfo{
67+
Key: name,
68+
Name: name,
69+
URL: fmt.Sprintf("%sapi/v1/licenses/%s", setting.AppURL, url.PathEscape(name)),
70+
Body: string(text),
71+
// This is for combatibilty with the GitHub API. This Text is for some reason added to each License response.
72+
Implementation: "Create a text file (typically named LICENSE or LICENSE.txt) in the root of your source code and copy the text of the license into the file",
73+
}
74+
75+
ctx.JSON(http.StatusOK, response)
76+
}

routers/api/v1/swagger/misc.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,20 @@ type swaggerResponseServerVersion struct {
1414
Body api.ServerVersion `json:"body"`
1515
}
1616

17+
// LicenseTemplateList
18+
// swagger:response LicenseTemplateList
19+
type swaggerResponseLicensesTemplateList struct {
20+
// in:body
21+
Body []api.LicensesTemplateListEntry `json:"body"`
22+
}
23+
24+
// LicenseTemplateInfo
25+
// swagger:response LicenseTemplateInfo
26+
type swaggerResponseLicenseTemplateInfo struct {
27+
// in:body
28+
Body api.LicenseTemplateInfo `json:"body"`
29+
}
30+
1731
// StringSlice
1832
// swagger:response StringSlice
1933
type swaggerResponseStringSlice struct {

templates/admin/cron.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<td><button type="submit" class="ui green button" name="op" value="{{.Name}}" title="{{$.locale.Tr "admin.dashboard.operation_run"}}">{{svg "octicon-triangle-right"}}</button></td>
2222
<td>{{$.locale.Tr (printf "admin.dashboard.%s" .Name)}}</td>
2323
<td>{{.Spec}}</td>
24-
<td>{{DateTime "full" (DateFmtLong .Next)}}</td>
24+
<td>{{DateTime "full" .Next}}</td>
2525
<td>{{if gt .Prev.Year 1}}{{DateTime "full" .Prev}}{{else}}N/A{{end}}</td>
2626
<td>{{.ExecTimes}}</td>
2727
<td {{if ne .Status ""}}data-tooltip-content="{{.FormatLastMessage $.locale}}"{{end}} >{{if eq .Status ""}}—{{else if eq .Status "finished"}}{{svg "octicon-check" 16}}{{else}}{{svg "octicon-x" 16}}{{end}}</td>

templates/shared/actions/runner_list.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
<th>{{.locale.Tr "actions.runners.owner_type"}}</th>
5353
<th>{{.locale.Tr "actions.runners.labels"}}</th>
5454
<th>{{.locale.Tr "actions.runners.last_online"}}</th>
55-
<th></th>
55+
<th>{{.locale.Tr "edit"}}</th>
5656
</tr>
5757
</thead>
5858
<tbody>

templates/swagger/v1_json.tmpl

Lines changed: 107 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright 2023 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package integration
5+
6+
import (
7+
"fmt"
8+
"net/http"
9+
"net/url"
10+
"testing"
11+
12+
"code.gitea.io/gitea/modules/options"
13+
repo_module "code.gitea.io/gitea/modules/repository"
14+
api "code.gitea.io/gitea/modules/structs"
15+
"code.gitea.io/gitea/tests"
16+
17+
"github.com/stretchr/testify/assert"
18+
)
19+
20+
func TestAPIListLicenseTemplates(t *testing.T) {
21+
defer tests.PrepareTestEnv(t)()
22+
23+
req := NewRequest(t, "GET", "/api/v1/licenses")
24+
resp := MakeRequest(t, req, http.StatusOK)
25+
26+
// This tests if the API returns a list of strings
27+
var licenseList []api.LicensesTemplateListEntry
28+
DecodeJSON(t, resp, &licenseList)
29+
}
30+
31+
func TestAPIGetLicenseTemplateInfo(t *testing.T) {
32+
defer tests.PrepareTestEnv(t)()
33+
34+
// If Gitea has for some reason no License templates, we need to skip this test
35+
if len(repo_module.Licenses) == 0 {
36+
return
37+
}
38+
39+
// Use the first template for the test
40+
licenseName := repo_module.Licenses[0]
41+
42+
urlStr := fmt.Sprintf("/api/v1/licenses/%s", url.PathEscape(licenseName))
43+
req := NewRequest(t, "GET", urlStr)
44+
resp := MakeRequest(t, req, http.StatusOK)
45+
46+
var licenseInfo api.LicenseTemplateInfo
47+
DecodeJSON(t, resp, &licenseInfo)
48+
49+
// We get the text of the template here
50+
text, _ := options.License(licenseName)
51+
52+
assert.Equal(t, licenseInfo.Key, licenseName)
53+
assert.Equal(t, licenseInfo.Name, licenseName)
54+
assert.Equal(t, licenseInfo.Body, string(text))
55+
}

web_src/css/features/codeeditor.css

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,18 @@
3131
.monaco-scrollable-element > .scrollbar > .slider:active {
3232
background: var(--color-primary-dark-2) !important;
3333
}
34+
35+
/* fomantic styles destroy this element only visible on IOS, restore it */
36+
.monaco-editor .iPadShowKeyboard {
37+
border: none !important;
38+
width: 58px !important;
39+
min-width: 0 !important;
40+
height: 36px !important;
41+
min-height: 0 !important;
42+
margin: 0 !important;
43+
padding: 0 !important;
44+
position: absolute !important;
45+
resize: none !important;
46+
overflow: hidden !important;
47+
border-radius: 4px !important;
48+
}

0 commit comments

Comments
 (0)