Giter Site home page Giter Site logo

filabel's Introduction

filabel

Build Status

Tool for labeling PRs at GitHub by globs.

How to run as CLI


Usage: filabel.py [OPTIONS] [REPOSLUGS]...

  CLI tool for filename-pattern-based labeling of GitHub PRs

Options:
  -s, --state [open|closed|all]   Filter pulls by state.  [default: open]
  -d, --delete-old / -D, --no-delete-old
                                  Delete labels that do not match anymore.
                                  [default: True]
  -b, --base BRANCH               Filter pulls by base (PR target) branch
                                  name.
  -a, --config-auth FILENAME      File with authorization configuration.
  -l, --config-labels FILENAME    File with labels configuration.
  --help                          Show this message and exit.

How to deploy to Heroku (web based app)

clone the repo
heroku create
git push heroku web
heroku config:set FILABEL_CONFIG=./test/fixtures/labels.abc.cfg
heroku config:set GH_TOKEN=---your token---
heroku config:set GH_USER=---your username---
heroku config:set GH_SECRET=---your github secret---

How to run tests

Just clone the repository, and run:

python setup.py test

This will run the tests, which are split up into three parts: CLI test, web (flask) tests and unit tests of internal funtions. In cases when environment variable GH_TOKEN is not specified, requests to GitHub API will be replayed from 'cassettes'. For this type of mocking I've used library betamax.

How to create new betamax cassettes

If you want to create your own replays of GitHub API requests (so called cassettes), just set GH_TOKEN variable. This will override existing jsons in test/fixtures/cassettes/. For this you need to create GitHub repos first. You can create those repos in your GitHub accound by running script:

bash ./test_environment/setup.sh

You will need to have hub command line tool installed. After cassettes are created; you can safely remove repositories in your GitHub accont by running script delete.sh from the same directory.

filabel's People

Contributors

hroncok avatar j-sokol avatar

Watchers

 avatar  avatar  avatar

filabel's Issues

Problem with web templates

After successful installation, an error occurs with web templates (version v0.3.1):

>       raise TemplateNotFound(template)
E       jinja2.exceptions.TemplateNotFound: template.html

__venv__/lib64/python3.6/site-packages/flask/templating.py:86: TemplateNotFound

Caused by no templates installed:

% ll env/lib/python3.6/site-packages/filabel_sokolja2-0.3.1.3-py3.6.egg/filabel/
total 28
-rw-rw-r--. 1 sushi sushi 3038 Nov  5 09:06 cli.py
-rw-rw-r--. 1 sushi sushi  318 Nov  5 09:06 config.py
-rw-rw-r--. 1 sushi sushi 5558 Nov  5 09:06 github.py
-rw-rw-r--. 1 sushi sushi   67 Nov  5 09:06 __init__.py
-rw-rw-r--. 1 sushi sushi   48 Nov  5 09:06 __main__.py
drwxrwxr-x. 2 sushi sushi  160 Nov  5 09:06 __pycache__/
-rw-rw-r--. 1 sushi sushi 3596 Nov  5 09:06 web.py

Testing

There are some important things uncovered by tests:

  • if application reacts to webhook of pull request change (you test only ping) and calls some internal methods appropriately
  • if CLI prints something on output while running and calls some internal methods appropriately

Also, you should try to avoid DeprecationWarning. You are using parametrized session, where it is not suitable. Long "static data" in code are not nice - it should be in fixtures.

When recording my own cassettes, it will make some tests fail probably because you are using hardcoded j-sokol/mi-pyt-test-repo...

___________________________________________________________ test_post_labels ___________________________________________________________

betamax_parametrized_session = <requests.sessions.Session object at 0x7f52f1f845f8>

    def test_post_labels(betamax_parametrized_session):
        """Test whether filabel posts a label"""
        github = filabel.github.GitHub(token, session=betamax_parametrized_session)
    
        slug = 'j-sokol/mi-pyt-test-repo'
>       ret = github.post_label(slug, '5', 'ddd')

test/test_internals.py:109: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <filabel.github.GitHub object at 0x7f52f1f84710>, slug = 'j-sokol/mi-pyt-test-repo', pull_request_number = '5', label = 'ddd'

    def post_label(self, slug, pull_request_number, label):
        response = self.session.post("{0}/repos/{1}/issues/{2}/labels".format(github_api_url, slug, pull_request_number, label), json=[label])
        # print( response.status_code, response.text)
        if response.status_code != 200:
>           raise Exception('POSTing label failed.')
E           Exception: POSTing label failed.

filabel/github.py:74: Exception
__________________________________________________________ test_delete_labels __________________________________________________________

betamax_parametrized_session = <requests.sessions.Session object at 0x7f52f1f3e898>

    def test_delete_labels(betamax_parametrized_session):
        """Test whether filabel posts a label"""
        github = filabel.github.GitHub(token, session=betamax_parametrized_session)
    
        slug = 'j-sokol/mi-pyt-test-repo'
>       ret = github.delete_label(slug, '5', 'ddd')

test/test_internals.py:119: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <filabel.github.GitHub object at 0x7f52f1f3e860>, slug = 'j-sokol/mi-pyt-test-repo', pull_request_number = '5', label = 'ddd'

    def delete_label(self, slug, pull_request_number, label):
        response = self.session.delete("{0}/repos/{1}/issues/{2}/labels/{3}".format(github_api_url, slug, pull_request_number, label))
        if response.status_code != 200:
>           raise Exception('DELETing label failed.')
E           Exception: DELETing label failed.

filabel/github.py:66: Exception

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.