Get Travis Shield on Github to Reflect Selected Branch Status

Right now I can get my travis shield to either reflect the latest run, or a specific branch, irrespective of what branch I select in my github project page. I can do this by either leaving out or specifying the branch name at the end of the URL. Instead, I would like to get the shield corresponding to the selected branch. In other words, each time I select a different branch, the URL to the travis shield in my README.md file would change.

In SVN you could use SVN keywords to implement something of the sort by modifying the shield URL with the branch name (or something like it). This QA provides some alternatives for git, but:

  • I'd prefer to avoid relying on shell scripts
  • I don't think keyword expansion will work because I need the files to be different on the Github side, not on my local computer (hopefully I'm just wrong about this)
  • Any ideas? Hopefully I'm just missing something silly. Feels like there has to be a really easy way of doing this.


    I make use of Travis build shields for miniCRAN, and the solution is quite simple.

    Note the addition of ?branch=... at the end of each travis shield link.

    Here is an extract from the README.md :

    **Build status**
    
    master: 
    [![Build Status](https://travis-ci.org/andrie/miniCRAN.svg?branch=master)](https://travis-ci.org/andrie/miniCRAN)
    release:
    [![Build Status](https://travis-ci.org/andrie/miniCRAN.svg?branch=release)](https://travis-ci.org/andrie/miniCRAN)
    dev: [![Build Status](https://travis-ci.org/andrie/miniCRAN.svg?branch=dev)](https://travis-ci.org/andrie/miniCRAN)
    

    This results in:

    Build status

    master: release: dev:


    This is not a perfect solution, but if you're already knit -ing your README from a README.Rmd, there's no added cost. Basically, you can use a system call in your README.Rmd to dynamically generate the Travis-CI shield based on whatever branch you're working in. It will be up to date and branch-specific as long as you always knit before pushing to GitHub.

    Here's a simple example:

    # Example README.Rmd
    
    Here's a branch specific shield:
    
    ```{r, echo=FALSE, eval=TRUE, results="asis"}
    travis_url <- "https://travis-ci.org/RevolutionAnalytics/miniCRAN.svg?branch="
    shield <- paste0("[![Build Status](",
                     travis_url,
                     system("git rev-parse --abbrev-ref HEAD", intern = TRUE),
                     ")](https://travis-ci.org/RevolutionAnalytics/miniCRAN)")
    cat(shield)
    ```
    

    The result will be like this:

    # Example README.Rmd
    
    Here's a branch specific shield:
    
    [![Build Status](https://travis-ci.org/RevolutionAnalytics/miniCRAN.svg?branch=master)](https://travis-ci.org/RevolutionAnalytics/miniCRAN)
    

    but the URL will point to whatever branch you're currently working on.

    Note: h/t to this answer for the relevant git command to detect the current branch name.

    链接地址: http://www.djcxy.com/p/19506.html

    上一篇: 在构建过程中获取git分支名称

    下一篇: 在Github上获取Travis Shield来反映选定的分支状态