Skip to content

Commit

Permalink
Escape hyphens in img.shields.io urls
Browse files Browse the repository at this point in the history
  • Loading branch information
mcspr committed Dec 28, 2018
1 parent eb249dd commit a53dee7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -3,7 +3,7 @@
ESPurna ("spark" in Catalan) is a custom firmware for ESP8285/ESP8266 based smart switches, lights and sensors.
It uses the Arduino Core for ESP8266 framework and a number of 3rd party libraries.

[![version](https://img.shields.io/badge/version-1.13.4-dev-brightgreen.svg)](CHANGELOG.md)
[![version](https://img.shields.io/badge/version-1.13.4--dev-brightgreen.svg)](CHANGELOG.md)
[![branch](https://img.shields.io/badge/branch-dev-orange.svg)](https://github.com/xoseperez/espurna/tree/dev/)
[![license](https://img.shields.io/github/license/xoseperez/espurna.svg)](LICENSE)
[![travis](https://travis-ci.org/xoseperez/espurna.svg?branch=dev)](https://travis-ci.org/xoseperez/espurna)
Expand Down
26 changes: 19 additions & 7 deletions pre-commit
Expand Up @@ -16,6 +16,7 @@ Copy this file to .git/hooks/

import os
import sys
import string
import re

from subprocess import call, check_output
Expand All @@ -37,6 +38,14 @@ if sys.version_info[0] < 3:
FileInput = FileInputCtx


class CustomFormatter(string.Formatter):
def format_field(self, value, spec):
if spec == "escape_hyphen":
return value.replace("-", "--")
else:
return super(CustomFormatter, self).format_field(value, spec)


def run(cmd, cwd=None):
out = check_output(cmd, cwd=cwd)
out = out.decode("latin1").strip()
Expand Down Expand Up @@ -79,12 +88,13 @@ def espurna_get_version(base, version_h="code/espurna/config/version.h"):

return version


TEMPLATES = {
"![travis]": "[![travis](https://travis-ci.org/{USER}/{REPO}.svg?branch={BRANCH})]" \
"![travis]": "[![travis](https://travis-ci.org/{USER}/{REPO}.svg?branch={BRANCH})]"
"(https://travis-ci.org/{USER}/{REPO})\n",
"![version]": "[![version](https://img.shields.io/badge/version-{VERSION}-brightgreen.svg)](CHANGELOG.md)\n",
"![branch]": "[![branch](https://img.shields.io/badge/branch-{BRANCH}-orange.svg)]" \
"(https://github.com/{USER}/{REPO}/tree/{BRANCH}/)\n"
"![version]": "[![version](https://img.shields.io/badge/version-{VERSION:escape_hyphen}-brightgreen.svg)](CHANGELOG.md)\n",
"![branch]": "[![branch](https://img.shields.io/badge/branch-{BRANCH:escape_hyphen}-orange.svg)]"
"(https://github.com/{USER}/{REPO}/tree/{BRANCH}/)\n",
}

README = "README.md"
Expand All @@ -98,10 +108,12 @@ if __name__ == "__main__":
"USER": user,
"REPO": repo,
"BRANCH": git_branch(),
"VERSION": espurna_get_version(base)
"VERSION": espurna_get_version(base),
}

formatter = CustomFormatter()
templates = [
(k, tmpl.format(**fmt))
(k, formatter.format(tmpl, **fmt))
for k, tmpl in TEMPLATES.items()
]

Expand All @@ -121,4 +133,4 @@ if __name__ == "__main__":
if call(["git", "add", README]):
sys.exit(1)

sys.exit(0);
sys.exit(0)

0 comments on commit a53dee7

Please sign in to comment.