[aur-dev] [PATCH 1/2] git-serve: Add support for (un-)flagging packages
Add support for flagging or unflagging packages from the SSH interface. The syntax is `flag <pkgbase> <comment>` resp. `unflag <pkgbase>`. Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org> --- aurweb/git/serve.py | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/aurweb/git/serve.py b/aurweb/git/serve.py index 476aea8..08c6541 100755 --- a/aurweb/git/serve.py +++ b/aurweb/git/serve.py @@ -269,6 +269,52 @@ def pkgbase_disown(pkgbase, user, privileged): conn.close() +def pkgbase_flag(pkgbase, user, comment): + pkgbase_id = pkgbase_from_name(pkgbase) + if not pkgbase_id: + die('{:s}: package base not found: {:s}'.format(action, pkgbase)) + + conn = aurweb.db.Connection() + + cur = conn.execute("SELECT ID FROM Users WHERE Username = ?", [user]) + userid = cur.fetchone()[0] + if userid == 0: + die('{:s}: unknown user: {:s}'.format(action, user)) + + now = int(time.time()) + conn.execute("UPDATE PackageBases SET " + + "OutOfDateTS = ?, FlaggerUID = ?, FlaggerComment = ? " + + "WHERE ID = ? AND OutOfDateTS IS NULL", + [now, userid, comment, pkgbase_id]) + + conn.commit() + + subprocess.Popen((notify_cmd, 'flag', str(userid), str(pkgbase_id))) + + +def pkgbase_unflag(pkgbase, user): + pkgbase_id = pkgbase_from_name(pkgbase) + if not pkgbase_id: + die('{:s}: package base not found: {:s}'.format(action, pkgbase)) + + conn = aurweb.db.Connection() + + cur = conn.execute("SELECT ID FROM Users WHERE Username = ?", [user]) + userid = cur.fetchone()[0] + if userid == 0: + die('{:s}: unknown user: {:s}'.format(action, user)) + + if user in pkgbase_get_comaintainers(pkgbase): + conn.execute("UPDATE PackageBases SET OutOfDateTS = NULL " + + "WHERE ID = ?", [pkgbase_id]) + else: + conn.execute("UPDATE PackageBases SET OutOfDateTS = NULL " + + "WHERE ID = ? AND (MaintainerUID = ? OR FlaggerUID = ?)", + [pkgbase_id, userid, userid]) + + conn.commit() + + def pkgbase_set_keywords(pkgbase, keywords): pkgbase_id = pkgbase_from_name(pkgbase) if not pkgbase_id: @@ -422,6 +468,28 @@ def main(): pkgbase = cmdargv[1] pkgbase_disown(pkgbase, user, privileged) + elif action == 'flag': + if len(cmdargv) < 2: + die_with_help("{:s}: missing repository name".format(action)) + if len(cmdargv) < 3: + die_with_help("{:s}: missing comment".format(action)) + if len(cmdargv) > 3: + die_with_help("{:s}: too many arguments".format(action)) + + pkgbase = cmdargv[1] + comment = cmdargv[2] + if len(comment) < 3: + die_with_help("{:s}: comment is too short".format(action)) + + pkgbase_flag(pkgbase, user, comment) + elif action == 'unflag': + if len(cmdargv) < 2: + die_with_help("{:s}: missing repository name".format(action)) + if len(cmdargv) > 2: + die_with_help("{:s}: too many arguments".format(action)) + + pkgbase = cmdargv[1] + pkgbase_unflag(pkgbase, user) elif action == 'set-comaintainers': if len(cmdargv) < 2: die_with_help("{:s}: missing repository name".format(action)) @@ -433,12 +501,14 @@ def main(): cmds = { "adopt <name>": "Adopt a package base.", "disown <name>": "Disown a package base.", + "flag <name> <comment>": "Flag a package base out-of-date.", "help": "Show this help message and exit.", "list-repos": "List all your repositories.", "restore <name>": "Restore a deleted package base.", "set-comaintainers <name> [...]": "Set package base co-maintainers.", "set-keywords <name> [...]": "Change package base keywords.", "setup-repo <name>": "Create a repository (deprecated).", + "unflag <name>": "Remove out-of-date flag from a package base.", "git-receive-pack": "Internal command used with Git.", "git-upload-pack": "Internal command used with Git.", } -- 2.11.0
Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org> --- test/t1200-git-serve.sh | 63 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/test/t1200-git-serve.sh b/test/t1200-git-serve.sh index 6fa6f95..d422c48 100755 --- a/test/t1200-git-serve.sh +++ b/test/t1200-git-serve.sh @@ -351,4 +351,67 @@ test_expect_success "Check whether package requests are closed when disowning." test_cmp actual expected ' +test_expect_success "Flag a package base out-of-date." ' + SSH_ORIGINAL_COMMAND="flag foobar Because." AUR_USER=user2 AUR_PRIVILEGED=0 \ + "$GIT_SERVE" 2>&1 && + cat >expected <<-EOF && + 1|Because. + EOF + echo "SELECT OutOfDateTS IS NOT NULL, FlaggerComment FROM PackageBases WHERE ID = 3;" | \ + sqlite3 aur.db >actual && + test_cmp expected actual +' + +test_expect_success "Unflag a package base as flagger." ' + SSH_ORIGINAL_COMMAND="unflag foobar" AUR_USER=user2 AUR_PRIVILEGED=0 \ + "$GIT_SERVE" 2>&1 && + cat >expected <<-EOF && + 0|Because. + EOF + echo "SELECT OutOfDateTS IS NOT NULL, FlaggerComment FROM PackageBases WHERE ID = 3;" | \ + sqlite3 aur.db >actual && + test_cmp expected actual +' + +test_expect_success "Unflag a package base as maintainer." ' + SSH_ORIGINAL_COMMAND="adopt foobar" AUR_USER=user AUR_PRIVILEGED=0 \ + "$GIT_SERVE" 2>&1 && + SSH_ORIGINAL_COMMAND="flag foobar Because." AUR_USER=user2 AUR_PRIVILEGED=0 \ + "$GIT_SERVE" 2>&1 && + SSH_ORIGINAL_COMMAND="unflag foobar" AUR_USER=user AUR_PRIVILEGED=0 \ + "$GIT_SERVE" 2>&1 && + cat >expected <<-EOF && + 0|Because. + EOF + echo "SELECT OutOfDateTS IS NOT NULL, FlaggerComment FROM PackageBases WHERE ID = 3;" | \ + sqlite3 aur.db >actual && + test_cmp expected actual +' + +test_expect_success "Unflag a package base as random user." ' + SSH_ORIGINAL_COMMAND="flag foobar Because." AUR_USER=user2 AUR_PRIVILEGED=0 \ + "$GIT_SERVE" 2>&1 && + SSH_ORIGINAL_COMMAND="unflag foobar" AUR_USER=user3 AUR_PRIVILEGED=0 \ + "$GIT_SERVE" 2>&1 && + cat >expected <<-EOF && + 1|Because. + EOF + echo "SELECT OutOfDateTS IS NOT NULL, FlaggerComment FROM PackageBases WHERE ID = 3;" | \ + sqlite3 aur.db >actual && + test_cmp expected actual +' + +test_expect_success "Flag using a comment which is too short." ' + SSH_ORIGINAL_COMMAND="unflag foobar" AUR_USER=user2 AUR_PRIVILEGED=0 \ + "$GIT_SERVE" 2>&1 && + SSH_ORIGINAL_COMMAND="flag foobar xx" AUR_USER=user2 AUR_PRIVILEGED=0 \ + test_must_fail "$GIT_SERVE" 2>&1 && + cat >expected <<-EOF && + 0|Because. + EOF + echo "SELECT OutOfDateTS IS NOT NULL, FlaggerComment FROM PackageBases WHERE ID = 3;" | \ + sqlite3 aur.db >actual && + test_cmp expected actual +' + test_done -- 2.11.0
participants (1)
-
Lukas Fleischer