-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Add simple update checker to Gitea #17212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
techknowlogick
merged 19 commits into
go-gitea:main
from
techknowlogick:update-checker-cron
Oct 16, 2021
Merged
Changes from 3 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
e7467b5
Add simple update checker to Gitea
techknowlogick b73aa6c
update struct and remove comments
techknowlogick b6ef89b
fix lint
techknowlogick 5d13cb5
Update custom/conf/app.example.ini
techknowlogick c1aa2fb
Update docs/content/doc/advanced/config-cheat-sheet.en-us.md
techknowlogick 57dc076
Update custom/conf/app.example.ini
techknowlogick 6df9747
Update docs/content/doc/advanced/config-cheat-sheet.en-us.md
techknowlogick 28c36c7
Update docs/content/doc/advanced/config-cheat-sheet.en-us.md
techknowlogick 2fcd728
Update docs/content/doc/advanced/config-cheat-sheet.en-us.md
techknowlogick c1b875e
Merge branch 'main' into update-checker-cron
6543 e67c006
Update modules/cron/tasks_extended.go
techknowlogick b891967
Update custom/conf/app.example.ini
techknowlogick fd13167
Merge branch 'main' into update-checker-cron
6543 dd118f4
Merge remote-tracking branch 'origin/main' into update-checker-cron
techknowlogick 4e80fb0
take PR feedback into account and display banner on admin dashboard f…
techknowlogick 0cfd1d8
Add more detailed message
techknowlogick 13c631b
placate lint
techknowlogick fc77ce3
update per feedback
techknowlogick 0b2de8a
Merge branch 'main' into update-checker-cron
techknowlogick File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright 2021 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package models | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"io/ioutil" | ||
"net/http" | ||
|
||
"code.gitea.io/gitea/modules/proxy" | ||
"code.gitea.io/gitea/modules/setting" | ||
|
||
"github.com/hashicorp/go-version" | ||
) | ||
|
||
// GiteaUpdateChecker returns error when new version of Gitea is available | ||
techknowlogick marked this conversation as resolved.
Show resolved
Hide resolved
|
||
func GiteaUpdateChecker(httpEndpoint string) error { | ||
httpClient := &http.Client{ | ||
Transport: &http.Transport{ | ||
Proxy: proxy.Proxy(), | ||
}, | ||
} | ||
|
||
req, err := http.NewRequest("GET", httpEndpoint, nil) | ||
if err != nil { | ||
return err | ||
} | ||
resp, err := httpClient.Do(req) | ||
if err != nil { | ||
return err | ||
} | ||
defer resp.Body.Close() | ||
body, err := ioutil.ReadAll(resp.Body) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
type v struct { | ||
Latest struct { | ||
Version string `json:"version"` | ||
} `json:"latest"` | ||
} | ||
ver := v{} | ||
err = json.Unmarshal(body, &ver) | ||
techknowlogick marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
giteaVersion, _ := version.NewVersion(setting.AppVer) | ||
updateVersion, _ := version.NewVersion(ver.Latest.Version) | ||
if giteaVersion.LessThan(updateVersion) { | ||
return fmt.Errorf("Newer version of Gitea available: %s Check the blog for more details https://blog.gitea.io", ver.Latest.Version) | ||
techknowlogick marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
return nil | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.