You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
3.5 KiB

#!/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()