Added setup-gitea script

main
Aaron Rainbolt 2 years ago
parent a9bfd762b3
commit 68b4daa0ac

@ -9,3 +9,15 @@ lubuntu-tools is designed to be the great catch-all bucket for all things Lubunt
All files are assumed to be licensed as GPL-3.0+, unless otherwise stated in the file itself or its accompanying documentation. All files are assumed to be licensed as GPL-3.0+, unless otherwise stated in the file itself or its accompanying documentation.
Everything here should have documentation associated with it, or else it will become like everything else that's thrown in a junk drawer. :P Put a blurb about what each tool is and what it does here in the README. If it needs more extensive documentation, write a short summary here, put the tool in its own folder, and add some documentation alongside it there. Everything here should have documentation associated with it, or else it will become like everything else that's thrown in a junk drawer. :P Put a blurb about what each tool is and what it does here in the README. If it needs more extensive documentation, write a short summary here, put the tool in its own folder, and add some documentation alongside it there.
---
##setup-gitea
Gets Lubuntu packaging repos ready for the next release. For each repo you tell it to affect, it will clone it, checkout the branch for the previous release, create a branch for the new release based on that, and then push it and set the new branch as the default branch of the repo.
To use it, open the setup-gitea.py file, and change the variables at the beginning as appropriate. Then open the repo-list file (which ought to be alongside the setup-gitea.py file), and make sure that every repo you want it to affect is in the file. Then do "python3 setup-gitea.py" and it should do its magic.
It's probably safe to include repos that the script shouldn't affect in the repo-list file, as any repos that don't have an ubuntu/PREVIOUSRELEASE branch will be skipped by the script. However, this script does make permanent (though reversible) changes to the repos it affects, so it's worth exercising caution anyway.
You will need a username, password, and API key into Lubuntu's Gitea instance in order to run the script and have it work. Additionally, your user will need the necessary privileges to manage the repos that you intend to change.

@ -0,0 +1,74 @@
#!/usr/bin/env python3
# Copyright (C) 2018-2022 Lubuntu Team
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import tempfile
import os
import subprocess
import requests
RELEASE = "lunar"
PREVRELEASE = "kinetic"
REPOLISTPATH = "./repo-list"
CLONEBASE = "https://username:password@git.lubuntu.me/Lubuntu/"
APITOKEN = "apitoken"
# NOTE: When using Git management functions in here, use os.chdir() FIRST to select the directory you want to be affected. All Git management functions operate in the current working directory.
def gitclone(repoURI): # Clones a Git repo in the current os dir.
subprocess.run(["git", "clone", repoURI])
def gitcheckout(checkoutTarget): # Checks out a branch or tag in the current Git repo.
subprocess.run(["git", "checkout", checkoutTarget])
def gitbranch(newBranch): # Creates a new branch in the current Git repo.
subprocess.run(["git", "branch", newBranch])
def gitpush(mode): # Pushes the current Git repo to the currently selected remote.
subprocess.run(["git", "push", mode])
def gitcurrentbranch(): # Gets the name of the current branch of the current Git repo and returns it as a string.
gitResult = subprocess.run(["git", "branch", "--show-current"], capture_output=True, encoding="utf-8")
return gitResult.stdout
def main():
with tempfile.TemporaryDirectory() as workingdir:
for line in open(REPOLISTPATH):
repository = line.strip("\n")
print("Acting on " + repository + "...")
# Clone the repository and push the new branch
os.chdir(workingdir)
gitclone(CLONEBASE + repository + ".git")
os.chdir(repository)
gitcheckout("ubuntu/" + PREVRELEASE) # TODO: Change this to checkout "ci/stable" once Drone is set up.
repoWorks = True
currentBranch = gitcurrentbranch()
currentBranch = currentBranch.strip()
if currentBranch != "ubuntu/" + PREVRELEASE:
print("!!!!!!!!!!!!!!!!!!!!!!!!!! ALERT ALERT ALERT !!!!!!!!!!!!!!!!!! Failed to process repo" + repository + "!")
repoWorks = False
if repoWorks:
gitbranch("ubuntu/" + RELEASE) # This *may* fail but if it does we don't care since we just want to make sure the branch exists in the first place.
gitcheckout("ubuntu/" + RELEASE) # TODO: Is this line even necessary?
gitpush("--all")
print("Cloned " + repository + ".")
# Change the default branch in Gitea
r = requests.patch("https://git.lubuntu.me/api/v1/repos/Lubuntu/" + repository, headers={"Authorization": "token " + APITOKEN}, json={"default_branch": "ubuntu/" + RELEASE})
repoName = r.json()["name"]
repoDefaultBranch = r.json()["default_branch"]
print("Changed the default branch of " + repoName + " to " + repoDefaultBranch + " in Gitea.")
main()
Loading…
Cancel
Save