aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/gen_vimdoc.py6
-rwxr-xr-xscripts/pvscheck.sh2
-rw-r--r--scripts/squash_typos.py204
-rwxr-xr-xscripts/vim-patch.sh22
4 files changed, 221 insertions, 13 deletions
diff --git a/scripts/gen_vimdoc.py b/scripts/gen_vimdoc.py
index 18a2839702..2efa544c2e 100755
--- a/scripts/gen_vimdoc.py
+++ b/scripts/gen_vimdoc.py
@@ -950,6 +950,8 @@ def main(config, args):
os.remove(mpack_file)
output_dir = out_dir.format(target=target)
+ log.info("Generating documentation for %s in folder %s",
+ target, output_dir)
debug = args.log_level >= logging.DEBUG
p = subprocess.Popen(
['doxygen', '-'],
@@ -1105,7 +1107,8 @@ def filter_source(filename):
def parse_args():
targets = ', '.join(CONFIG.keys())
- ap = argparse.ArgumentParser()
+ ap = argparse.ArgumentParser(
+ description="Generate helpdoc from source code")
ap.add_argument(
"--log-level", "-l", choices=LOG_LEVELS.keys(),
default=logging.getLevelName(logging.ERROR), help="Set log verbosity"
@@ -1159,6 +1162,7 @@ if __name__ == "__main__":
print("Setting log level to %s" % args.log_level)
args.log_level = LOG_LEVELS[args.log_level]
log.setLevel(args.log_level)
+ log.addHandler(logging.StreamHandler())
if len(args.source_filter) > 0:
filter_source(args.source_filter[0])
diff --git a/scripts/pvscheck.sh b/scripts/pvscheck.sh
index f3371b485e..aa27c94f29 100755
--- a/scripts/pvscheck.sh
+++ b/scripts/pvscheck.sh
@@ -379,7 +379,7 @@ run_analysis() {(
--sourcetree-root . || true
rm -rf PVS-studio.{xml,err,tsk,html.d}
- local plog_args="PVS-studio.log --srcRoot . --excludedCodes V011"
+ local plog_args="PVS-studio.log --srcRoot . --excludedCodes V011,V1042"
plog-converter $plog_args --renderTypes xml --output PVS-studio.xml
plog-converter $plog_args --renderTypes errorfile --output PVS-studio.err
plog-converter $plog_args --renderTypes tasklist --output PVS-studio.tsk
diff --git a/scripts/squash_typos.py b/scripts/squash_typos.py
new file mode 100644
index 0000000000..305680f079
--- /dev/null
+++ b/scripts/squash_typos.py
@@ -0,0 +1,204 @@
+#!/usr/bin/env python
+"""
+
+This script squashes a PR tagged with the "typo" label into a single, dedicated
+"squash PR".
+
+"""
+
+import subprocess
+import sys
+import os
+
+
+def get_authors_and_emails_from_pr():
+ """
+
+ Return all contributing authors and their emails for the PR on current branch.
+ This includes co-authors, meaning that if two authors are credited for a
+ single commit, which is possible with GitHub, then both will get credited.
+
+ """
+
+ # Get a list of all authors involved in the pull request (including co-authors).
+ authors = subprocess.check_output(
+ ["gh", "pr", "view", "--json", "commits", "--jq", ".[][].authors.[].name"],
+ text=True,
+ ).splitlines()
+
+ # Get a list of emails of the aforementioned authors.
+ emails = subprocess.check_output(
+ ["gh", "pr", "view", "--json", "commits", "--jq", ".[][].authors.[].email"],
+ text=True,
+ ).splitlines()
+
+ authors_and_emails_unique = {
+ (author, mail) for author, mail in zip(authors, emails)
+ }
+
+ return sorted(authors_and_emails_unique)
+
+
+def rebase_onto_pr():
+ """
+
+ Rebase current branch onto the PR.
+
+ """
+
+ # Check out the pull request.
+ subprocess.call(["gh", "pr", "checkout", os.environ["PR_NUMBER"]])
+
+ # Change back to the original branch.
+ subprocess.call(["git", "switch", "-"])
+
+ # Rebase onto the pull request, aka include the commits in the pull request
+ # in the current branch. Abort with error message if rebase fails.
+
+ try:
+ subprocess.check_call(["git", "rebase", "-"])
+ except subprocess.CalledProcessError:
+ subprocess.call(["git", "rebase", "--abort"])
+ squash_url = subprocess.check_output(
+ ["gh", "pr", "view", "--json", "url", "--jq", ".url"], text=True
+ ).strip()
+
+ subprocess.call(
+ [
+ "gh",
+ "pr",
+ "comment",
+ os.environ["PR_NUMBER"],
+ "--body",
+ f"Your edit conflicts with an already scheduled fix \
+ ({squash_url}). Please check that batch PR whether your fix is \
+ already included; if not, then please wait until the batch PR \
+ is merged and then rebase your PR on top of master.",
+ ]
+ )
+
+ sys.exit(
+ f"\n\nERROR: Your edit conflicts with an already scheduled fix \
+{squash_url} \n\n"
+ )
+
+
+def squash_all_commits():
+ """
+
+ Squash all commits on the PR into a single commit. Credit all authors by
+ name and email.
+
+ """
+
+ default_branch = f"{os.environ['GITHUB_BASE_REF']}"
+ subprocess.call(["git", "reset", "--soft", default_branch])
+
+ authors_and_emails = get_authors_and_emails_from_pr()
+ commit_message_coauthors = "\n" + "\n".join(
+ [f"Co-authored-by: {i[0]} <{i[1]}>" for i in authors_and_emails]
+ )
+ subprocess.call(
+ ["git", "commit", "-m", "chore: typo fixes", "-m", commit_message_coauthors]
+ )
+
+
+def force_push(branch):
+ """
+
+ Like the name implies, force push <branch>.
+
+ """
+
+ gh_actor = os.environ["GITHUB_ACTOR"]
+ gh_token = os.environ["GITHUB_TOKEN"]
+ gh_repo = os.environ["GITHUB_REPOSITORY"]
+ subprocess.call(
+ [
+ "git",
+ "push",
+ "--force",
+ f"https://{gh_actor}:{gh_token}@github.com/{gh_repo}",
+ branch,
+ ]
+ )
+
+
+def checkout_branch(branch):
+ """
+
+ Create and checkout <branch>. Check if branch exists on remote, if so then
+ sync local branch to remote.
+
+ Return True if remote branch exists, else False.
+
+ """
+
+ # FIXME I'm not sure why the local branch isn't tracking the remote branch
+ # automatically. This works but I'm pretty sure it can be done in a more
+ # "elegant" fashion
+
+ show_ref_output = subprocess.check_output(["git", "show-ref"], text=True).strip()
+
+ if branch in show_ref_output:
+ subprocess.call(["git", "checkout", "-b", branch, f"origin/{branch}"])
+ return True
+
+ subprocess.call(["git", "checkout", "-b", branch])
+ return False
+
+
+def get_all_pr_urls(squash_branch_exists):
+ """
+
+ Return a list of URLs for the pull requests with the typo fixes. If a
+ squash branch exists then extract the URLs from the body text.
+
+ """
+
+ all_pr_urls = ""
+ if squash_branch_exists:
+ all_pr_urls += subprocess.check_output(
+ ["gh", "pr", "view", "--json", "body", "--jq", ".body"], text=True
+ )
+
+ all_pr_urls += subprocess.check_output(
+ ["gh", "pr", "view", os.environ["PR_NUMBER"], "--json", "url", "--jq", ".url"],
+ text=True,
+ ).strip()
+
+ return all_pr_urls
+
+
+def main():
+ squash_branch = "marvim/squash-typos"
+
+ squash_branch_exists = checkout_branch(squash_branch)
+
+ rebase_onto_pr()
+ force_push(squash_branch)
+
+ subprocess.call(
+ [
+ "gh",
+ "pr",
+ "create",
+ "--fill",
+ "--head",
+ squash_branch,
+ "--title",
+ "chore: typo fixes (automated)",
+ ]
+ )
+
+ squash_all_commits()
+ force_push(squash_branch)
+
+ all_pr_urls = get_all_pr_urls(squash_branch_exists)
+ subprocess.call(["gh", "pr", "edit", "--add-label", "typo", "--body", all_pr_urls])
+
+ subprocess.call(["gh", "pr", "close", os.environ["PR_NUMBER"]])
+
+
+if __name__ == "__main__":
+ main()
diff --git a/scripts/vim-patch.sh b/scripts/vim-patch.sh
index 4fd9711619..e9242c4dbe 100755
--- a/scripts/vim-patch.sh
+++ b/scripts/vim-patch.sh
@@ -326,12 +326,14 @@ stage_patch() {
return $ret
}
-hub_pr() {
- hub pull-request -m "$1"
+gh_pr() {
+ gh pr create --title "$1" --body "$2"
}
git_hub_pr() {
- git hub pull new -m "$1"
+ local pr_message
+ pr_message="$(printf '%s\n\n%s\n' "$1" "$2")"
+ git hub pull new -m "${pr_message}"
}
# shellcheck disable=SC2015
@@ -341,14 +343,14 @@ submit_pr() {
local push_first
push_first=1
local submit_fn
- if check_executable hub; then
- submit_fn="hub_pr"
+ if check_executable gh; then
+ submit_fn="gh_pr"
elif check_executable git-hub; then
push_first=0
submit_fn="git_hub_pr"
else
- >&2 echo "${BASENAME}: 'hub' or 'git-hub' not found in PATH or not executable."
- >&2 echo " Get it here: https://hub.github.com/"
+ >&2 echo "${BASENAME}: 'gh' or 'git-hub' not found in PATH or not executable."
+ >&2 echo " Get it here: https://cli.github.com/"
exit 1
fi
@@ -371,9 +373,7 @@ submit_pr() {
patches=(${patches[@]//vim-patch:}) # Remove 'vim-patch:' prefix for each item in array.
local pr_title="${patches[*]}" # Create space-separated string from array.
pr_title="${pr_title// /,}" # Replace spaces with commas.
-
- local pr_message
- pr_message="$(printf 'vim-patch:%s\n\n%s\n' "${pr_title#,}" "${pr_body}")"
+ pr_title="$(printf 'vim-patch:%s' "${pr_title#,}")"
if [[ $push_first -ne 0 ]]; then
echo "Pushing to 'origin/${checked_out_branch}'."
@@ -385,7 +385,7 @@ submit_pr() {
fi
echo "Creating pull request."
- output="$(${submit_fn} "${pr_message}" 2>&1)" &&
+ output="$(${submit_fn} "${pr_title}" "${pr_body}" 2>&1)" &&
msg_ok "${output}" ||
(msg_err "${output}"; false)