Odwoływanie się do bieżącej gałęzi w GitHubie readme.md

In my github repo ' s readme.md akta mam odznakę Travis-CI. Używam poniższego linku:

https://travis-ci.org/joegattnet/joegattnet_v3.png?branch=staging

Oczywistym problemem jest to, że gałąź jest zakodowana na twardo. Czy jest możliwe użycie jakiejś zmiennej tak, aby gałąź była aktualnie przeglądana?

Author: Joe Gatt, 2013-09-07

2 answers

Nic mi o tym nie wiadomo.
Wsparcie GitHub potwierdza (poprzez OP ' S comment)

Jedynym sposobem, aby to zrobić, byłoby przekazanie łącza przez moją własną usługę, która użyłaby nagłówka HTTP referrer Githuba, aby określić, która gałąź jest odwoływana, a następnie pobrać odpowiedni obraz z Travis CI

Wolałbym zrobić jedną odznakę Travis-CI na gałąź, aby czytelnik mógł wybrać lub rozważyć odpowiednią, gdy zobaczy README.md.


Aktualizacja 2016 (3 lata później): chociaż nic się nie zmieniło po stronie Githuba, fedorqui zgłasza w obejściu wspomnianym w "Get Travis Shield on Github to Reflect Selected Branch Status" przez Andrie.
Po prostu pokaż wszystkie gałęzie i odpowiednie odznaki TravisCI.

Jeśli masz tylko dwie lub trzy gałęzie, to może wystarczyć.
 48
Author: VonC,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-05-23 12:25:45

Obejrzałem ten problem z hakiem Git pre-commit, który ponownie zapisuje linię Travisa w README.md z aktualną gałęzią. Przykład użycia i kodu Pre-commit (Python) (dla zadanego pytania) są poniżej.

Użycie

dandye$ git checkout -b feature123 origin/master
Branch feature123 set up to track remote branch master from origin.
Switched to a new branch 'feature123'
dandye$ echo "* Feature123" >> README.md 
dandye$ git add README.md 
dandye$ git commit -m "Added Feature123"
Starting pre-commit hook...
Replacing:
    [![Build Status](https://travis-ci.org/joegattnet/joegattnet_v3.png?branch=master)][travis]

with:
    [![Build Status](https://travis-ci.org/joegattnet/joegattnet_v3.png?branch=feature123)][travis]

pre-commit hook complete.
[feature123 54897ee] Added Feature123
 1 file changed, 2 insertions(+), 1 deletion(-)
dandye$ cat README.md |grep "Build Status"
[![Build Status](https://travis-ci.org/joegattnet/joegattnet_v3.png?branch=feature123)][travis]
dandye$ 

Kod Pythona dla kodu przed zatwierdzeniem

dandye$ cat .git/hooks/pre-commit
#!/usr/bin/python
"""
Referencing current branch in github readme.md[1]

This pre-commit hook[2] updates the README.md file's
Travis badge with the current branch. Gist at[4].

[1] http://stackoverflow.com/questions/18673694/referencing-current-branch-in-github-readme-md
[2] http://www.git-scm.com/book/en/v2/Customizing-Git-Git-Hooks
[3] https://docs.travis-ci.com/user/status-images/
[4] https://gist.github.com/dandye/dfe0870a6a1151c89ed9
"""
import subprocess

# Hard-Coded for your repo (ToDo: get from remote?)
GITHUB_USER="joegattnet"
REPO="joegattnet_v3"

print "Starting pre-commit hook..."

BRANCH=subprocess.check_output(["git",
                                "rev-parse",
                                "--abbrev-ref",
                                "HEAD"]).strip()

# String with hard-coded values
# See Embedding Status Images[3] for alternate formats (private repos, svg, etc)

#  [![Build Status](https://travis-ci.org/
#  joegattnet/joegattnet_v3.png?
#  branch=staging)][travis]

# Output String with Variable substitution
travis="[![Build Status](https://travis-ci.org/" \
       "{GITHUB_USER}/{REPO}.png?" \
       "branch={BRANCH})][travis]\n".format(BRANCH=BRANCH,
                                            GITHUB_USER=GITHUB_USER,
                                            REPO=REPO)

sentinel_str="[![Build Status]"

readmelines=open("README.md").readlines()
with open("README.md", "w") as fh:
    for aline in readmelines:
        if sentinel_str in aline and travis != aline:
            print "Replacing:\n\t{aline}\nwith:\n\t{travis}".format(
                   aline=aline,
                   travis=travis)
            fh.write(travis)
        else:
            fh.write(aline)

subprocess.check_output(["git", "add", "README.md" ])

print "pre-commit hook complete."
 12
Author: Dan Dye,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-03-30 03:19:22