Giter VIP home page Giter VIP logo

gerrit-hooks's Introduction

Gerrit Hooks Argument Parsers

This library provides pre-built argparse.ArgumentParser instances, which return argpase.NameSpace object for gerrit's hooks (linked in the Resources section below).

It allows developers to get started with gerrit hooks faster, by getting the parsing of command-line arguments for the various hook types out of the way.

All hooks are supported.

Installation

pip install gerrit-hooks

Usage

Writing hooks using gerrit-hooks' argparsers is easy:

> gerrit/hooks/comment-added

#!/usr/bin/env/python3
import gerrit_hooks

options = gerrit_hooks.parse_options()

print("Change ID: {}".format(options.change))

...

Custom approval categories are supported as well - these must be added before calling gerrit_hooks.parse_options():

> gerrit/hooks/comment-added

#!/usr/bin/env/python3
import gerrit_hooks

# Let's assume you have a approval category with label 'level-of-amazingness
# We need to add this to the Hook Flag Definitions class
gerrit_hooks.add_custom_approval_category('level-of-amazingness')

options = gerrit_hooks.parse_options()

# The approval category can be accessed by the following attributes:
print("Level of Amazingness is: {}".format(options.level_of_amazingness))
print("Level of Amazingness was: {}".format(options.level_of_amazingness_oldValue))

...

Resources

Gerrit-Hooks Plugin

gerrit-hooks's People

Contributors

jf-ct avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

jf-ct

gerrit-hooks's Issues

When arguments are passed to script via $@ in bash script, quoted parameters like --author get truncated

This may not be a bug in the library, but it may be possible to set nargs="+" and then have some logic to do a ' '.join(gerrit_args.author) (and so on for similar fields)

So far I have had to do a workaround after parsing (using sys.argv) for the following fields:

  • --uploader
  • --change-owner
  • --author

Another similar issue occurs when Gerrit passes --topic without any argument, and the parser expects one to be there. (i.e. some of the configurations could be tweaked for certain options)

Maybe instead of _generate_parser() there could be an extra step before that like _generate_options() so that the options could be modified before the call to _generate_parser()

no handling for change-deleted hook

https://gerrit.googlesource.com/plugins/hooks/+/refs/heads/stable-2.15/src/main/resources/Documentation/hooks.md#change_deleted

Traceback (most recent call last):
  File "...", line ..., in <module>
    gerrit_parser = gerrit_hooks.build_parser_for(args.gerrit_event)
  File "/usr/local/lib/python3.5/dist-packages/gerrit_hooks/hook.py", line 37, in build_parser_for
    cli_flags = HookFlagDefinitions()[hook_type]
  File "/usr/local/lib/python3.5/dist-packages/gerrit_hooks/containers.py", line 172, in __getitem__
    flag_string = self.__mapping__[item]
KeyError: 'change-deleted'

Implement support for multiple args in hashtag-created hook

The current implementation of the hashtag-created hook would only allow one of each:

  1. --removed
  2. --added
  3. --hashtag

Support for multiple of these needs to be implemented, since bulk-changes to hashtags are currently not supported due to this limitation.

Add Auto-detection of Hook type

Currently, the developers have to define the type of hook they're writing, by passing a str to the build_parser_for() function (or using the HookType container class to do so).

Since the hook names are identical to the file names in the common case, add an auto-detection mechanism, to automatically select the appropriate parser to build.

It could then look like this:

import gerrit_hooks

options = gerrit_hooks.parse_options()

Where parse_options() would throw an error if we can't make anything of the current file-type.

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.