Skip to content

Instantly share code, notes, and snippets.

@vmx
Created May 2, 2018 21:19
Show Gist options
  • Save vmx/6ff564e93cf7c0a77866a4bcda19fdf5 to your computer and use it in GitHub Desktop.
Save vmx/6ff564e93cf7c0a77866a4bcda19fdf5 to your computer and use it in GitHub Desktop.
Add Module Lead Maintainer to an InterPlanetary project
#!/usr//bin/gawk -f
# This script modifies a package.json file. It removes the author and adds
# a lead maintainer given my the environment variables `LEAD_MAINTAINER_NAME`
# and `LEAD_MAINTAINER_EMAIL`.
{
key = $1
# Remove author
if(key == "\"author\":") {
next
}
if (key == "\"description\":") {
print $0
#print " \"leadMaintainer\": \"A Test <[email protected]>\""
print " \"leadMaintainer\": \"" ENVIRON["LEAD_MAINTAINER_NAME"] " <" ENVIRON["LEAD_MAINTAINER_EMAIL"] ">\","
next
}
print $0
}
#!/usr//bin/gawk -f
# This script modifies a README.md. It removes the Maintainer sectionand adds
# a Lead Mainter section given my the environment variables
# `LEAD_MAINTAINER_NAME` and `LEAD_MAINTAINER_GITHUB`.
BEGIN {
# True if line should be skipped
skip = 0
# True if we are within the Table of Contents section
table_of_contents = 0
}
{
headline = 0
if ($1 == "##") {
headline = 1
# New section stop skipping things
skip = 0
# New section, reset table of contents variable
table_of_contents = 0
#print "vmx: headline:" $2 $headline
}
# Remove Maintainers section
if (headline && $2 == "Maintainers") {
skip = 1
}
# Add the Lead Maintainer section before the Table of Contents
if (headline && $2 == "Table") {
print "## Lead Maintainer"
print ""
print "[" ENVIRON["LEAD_MAINTAINER_NAME"] "](https://github.com/" ENVIRON["LEAD_MAINTAINER_GITHUB"] ")"
print ""
table_of_contents = 1
}
# Remove Maintainers section from Table of Contents
if (table_of_contents && $1 == "-" && $2 == "[Maintainers](#maintainers)") {
next
}
if (skip) {
next
} else {
print $0
}
}
#!/bin/sh
# Run from the master branch of a project:
# LEAD_MAINTAINER_NAME='Volker Mische' LEAD_MAINTAINER_EMAIL='[email protected]' LEAD_MAINTAINER_GITHUB='vmx' /home/vmx/src/pl/scripts/lead-maintainer.sh
git pull
git checkout -b lead-maintainer
# Update package.json with lead maintainer
gawk -f /home/vmx/src/pl/scripts/lead-maintainer-package.awk -i inplace package.json
# Remove the Maintainer section from the README and add Lead Maintainer section
gawk -f /home/vmx/src/pl/scripts/lead-maintainer-readme.awk -i inplace README.md
# Commit the changes
git add package.json README.md
git commit -F- <<EOF
chore: add module Lead Maintainer
The Guidelines for the InterPlanetary JavaScript Projects [1] specify
that there is one Lead Maintainer for every module. This commit add
that information to the repository.
[1]: https://github.com/ipfs/community/blob/master/js-code-guidelines.md
EOF
# Push the changes without verification as it isn't a code change
git push origin lead-maintainer --no-verify
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment