Browse Source

Escape hyphens in img.shields.io urls

refactor-terminal
Max Prokhorov 5 years ago
parent
commit
a53dee766e
2 changed files with 20 additions and 8 deletions
  1. +1
    -1
      README.md
  2. +19
    -7
      pre-commit

+ 1
- 1
README.md View File

@ -3,7 +3,7 @@
ESPurna ("spark" in Catalan) is a custom firmware for ESP8285/ESP8266 based smart switches, lights and sensors. 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. 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/) [![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) [![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) [![travis](https://travis-ci.org/xoseperez/espurna.svg?branch=dev)](https://travis-ci.org/xoseperez/espurna)


+ 19
- 7
pre-commit View File

@ -16,6 +16,7 @@ Copy this file to .git/hooks/
import os import os
import sys import sys
import string
import re import re
from subprocess import call, check_output from subprocess import call, check_output
@ -37,6 +38,14 @@ if sys.version_info[0] < 3:
FileInput = FileInputCtx 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): def run(cmd, cwd=None):
out = check_output(cmd, cwd=cwd) out = check_output(cmd, cwd=cwd)
out = out.decode("latin1").strip() out = out.decode("latin1").strip()
@ -79,12 +88,13 @@ def espurna_get_version(base, version_h="code/espurna/config/version.h"):
return version return version
TEMPLATES = { 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", "(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" README = "README.md"
@ -98,10 +108,12 @@ if __name__ == "__main__":
"USER": user, "USER": user,
"REPO": repo, "REPO": repo,
"BRANCH": git_branch(), "BRANCH": git_branch(),
"VERSION": espurna_get_version(base)
"VERSION": espurna_get_version(base),
} }
formatter = CustomFormatter()
templates = [ templates = [
(k, tmpl.format(**fmt))
(k, formatter.format(tmpl, **fmt))
for k, tmpl in TEMPLATES.items() for k, tmpl in TEMPLATES.items()
] ]
@ -121,4 +133,4 @@ if __name__ == "__main__":
if call(["git", "add", README]): if call(["git", "add", README]):
sys.exit(1) sys.exit(1)
sys.exit(0);
sys.exit(0)

Loading…
Cancel
Save