1
0
mirror of https://github.com/CMiksche/gitea-auto-update synced 2025-12-10 16:07:23 +01:00

feat: get version from file

Add function to get the version from the gitea file if the web api does fail.

Should implement the idea from GH-8
This commit is contained in:
Christoph Miksche
2019-05-31 22:16:11 +02:00
parent b38143effc
commit 482df30496
4 changed files with 25 additions and 1 deletions

View File

@@ -49,3 +49,23 @@ def is_tool(name):
from shutil import which
return which(name) is not None
def parseFileVersion(string):
return string.split(" ")[2]
def getVersionFromFile():
version_string = os.popen(settings.gtfile+" -v").read()
return parseFileVersion(version_string)
# Function to get the current version
def getCurrentVersion():
try:
# Try to get the version from the file
current_version = getVersionFromFile()
except:
# Get the version via the web api if the file does fail
current_version = requests.get(settings.gtsite).json()['version']
if current_version.status_code != 200:
current_version = getVersionFromFile()
finally:
return current_version

View File

@@ -7,6 +7,7 @@ All rights reserved.
License: GNU General Public License
'''
# Gitea Site
# Optional - the script will get the version from the gitea file if you change the url to a empty string
gtsite = 'https://your-gitea-instance.com/api/v1/version'
# Gitea GitHub API URL for latest Relase
gtgithubapiurl = 'https://api.github.com/repos/go-gitea/gitea/releases/latest'

View File

@@ -29,5 +29,8 @@ class Tests(unittest.TestCase):
def testSuffix(self):
self.assertTrue(functions.checkVersion('1.9.0+dev-264-g8de76b6e6', '1.8.0'))
def testParseFileVersion(self):
self.assertEqual(functions.parseFileVersion('Gitea version 1.8.1 built with go1.12.2 : bindata, sqlite, sqlite_unlock_notify'), '1.8.1')
if __name__ == '__main__':
unittest.main()

View File

@@ -16,7 +16,7 @@ if not functions.is_tool("xz"):
quit()
# Version from gitea site
current_version = requests.get(settings.gtsite).json()['version']
current_version = functions.getCurrentVersion()
print ("current_version =", current_version)
# Get version tag from github and remove first char (v)
github_version_tag = requests.get(settings.gtgithubapiurl).json()['tag_name']