Module documentation¶
Module github¶
-
class
labelord.github.Label(name, color)¶ Bases:
objectClass that handle one github label.
Variables: - name (str) – Name of label
- color (str) – Color of label in hexadecimal format
-
class
labelord.github.LabelUpdater(session, config, runConfig)¶ Bases:
objectClass that handle all communication with GitHub api.
Variables: - session (Session) – authenticated connection session with GitHub
- config (Config) – Config object with loaded labelord config
- runConfig (dict) – dictionary with all arguments from console
-
add_label(repository, label)¶ Add label to repository, if there is some error, increase error counter
Parameters: - repository (
str) – target repository - label (
Label) – class Label with new label
Return type: None
Returns: None
- repository (
-
get_source_labels(repository)¶ Return source labels (how target repository should have) First use -t/–template_repo (even it was empty) Next try template-repo from config file from others section Last one is labels section in config file
Parameters: repository ( str) – repository from -t/–template-repo parameterReturn type: listReturns: list of Label classes
-
get_target_repositories()¶ Get list of target repositories, where update will be used First check parameter -a/–all_repos (use all accesable repos) Second try list of repos from repos section in config file If not found, quit with exit code 7
Return type: listReturns: list of repos Raises: SystemExit – if not repos found
-
print_log(repository, operationType, label, error)¶ Print one log line
Parameters: - repository (
str) – Repository specification - operationType (
str) – Operation type (UPD,DEL,ADD) - label (
Label) – Label class with new label - error (
str) – error message, if there war some error
Return type: None
Returns: None
- repository (
-
print_summary()¶ Print summary line based on -q/–quit and -v/–verbose parameters Each of them have another format If there were some errors, quit with exit code 10
Return type: None Returns: None Raises: SystemExit – if there is some error
-
remove_label(repository, label)¶ Remove label from repository, if there is some error, increase error counter
Parameters: - repository (
str) – target repository - label (
Label) – class Label, which should be deleted
Return type: None
Returns: None
- repository (
-
update_label(repository, label, oldLabel=None)¶ Update existing label in repository, if there is some error, increase error counter
Parameters: Return type: None
Returns: None
-
update_labels(newLabels, targetRepositories)¶ Change labels in given repositories
Parameters: - newLabels (
list) – list of new labels - targetRepositories (
list) – list of target repositories
Return type: None
Returns: None
- newLabels (
-
class
labelord.github.MyAuth(token: str)¶ Bases:
requests.auth.AuthBaseClass for authentication of requests
Variables: token (str) – authentication token for GitHub -
set_token(token)¶ Set token to class auth
Parameters: token (str) – GitHub token
-
-
labelord.github.find_label(label, iterable)¶ Find class Label in list of Label classes
- it -> founded old label
- type -> type of match
- 0 -> not found
- 1 -> name found, other color
- 2 -> name found, same color
- 3 -> name different case
Parameters: - label (
Label) – searched label - iterable (
list) – list of labels
Return type: tupleReturns: tuple (it, type)
-
labelord.github.get_list_labels(session, repository, exitProgram=True)¶ Get list of labels in given repository
Parameters: - session (
Session) – authenticated session - repository (
str) – target repository - exitProgram (
bool) – if False, program will not quit if repository not found, only return False
Return type: Union[list,bool]Returns: list of Labels / False
- session (
-
labelord.github.get_list_repos(session)¶ Get list of available repos
Parameters: session ( Session) – authenticated sessionReturn type: listReturns: list of available repos
-
labelord.github.load_config(cfg)¶ Load .cfg file and parse to Config object
Parameters: cfg ( str) – path to config fileReturn type: ConfigParserReturns: config file Object
-
labelord.github.load_token(config, token)¶ Load token from config file, if token given by parameter, just return this string
Parameters: - config (
ConfigParser) – config file object - token (
str) – token string
Return type: strReturns: token
Raises: SystemExit – if no token found
- config (
-
labelord.github.validate_response(response, exitProgram=True)¶ Validate response by status code
- 401 - code 4
- 404 - code 5
- response.ok == False - code 10
Parameters: - response (
Response) – response object from session - exitProgram (
bool) – if false, quit will be supprested
Return type: intReturns: error code
Raises: SystemExit – if exitProgram is tru
Module labelord¶
labelord¶
Main program group of click
| param ctx: | context for object passing |
|---|---|
| param config: | path to config file, default config.cfg |
| param token: | GITHUB token |
| return: | None |
labelord [OPTIONS] COMMAND [ARGS]...
Options
-
-c,--config<config>¶ Specify path to config file.
-
-t,--token<token>¶ Token for GitHub API.
-
--version¶ Show the version and exit.
Environment variables
list_labels¶
List of labels from repository :param ctx: context :param repository: name if repository :return: None
labelord list_labels [OPTIONS] REPOSITORY
Arguments
-
REPOSITORY¶ Required argument
list_repos¶
Command for repositories list :param ctx: context :return: None
labelord list_repos [OPTIONS]
run¶
Main program for copy labels and update labels
| param ctx: | context |
|---|---|
| param sourceRepository: | |
| source repository for source labels | |
| param allRepos: | flag if all repos should be updated |
| param mode: | mode -> update / replace |
| param quiet: | flag for quit mode |
| param verbose: | flag for verbose mode |
| param dryRun: | flag for dryRun mode |
| return: | None |
labelord run [OPTIONS] MODE
Options
-
-t,--template-repo<sourceRepository>¶ Source repository for labels
-
-a,--all-repos¶ Use all available repository
-
-q,--quiet¶ Quit print, no output to console
-
-v,--verbose¶ Debug info to console
-
-d,--dry-run¶ Run only testing instation, no changes at repos
Arguments
-
MODE¶ Required argument
run_server¶
Run server command :param ctx: context from click :param hostname: hostname for flask run :param port: port for flask run :param debug: enable debug mode :return: None
labelord run_server [OPTIONS]
Options
-
-h,--host<hostname>¶ Host name for start server
-
-p,--port<port>¶ Port for start server
-
-d,--debug¶ Enable flask server debug mode
Module server¶
-
class
labelord.server.LabelordWeb(*args, **kwargs)¶ Bases:
flask.app.FlaskCustom class for app, extend flask.Flask
-
inject_session(session)¶ Inject session to current app (for testing) :type session:
Session:param session: session class :rtype: None :return: None
-
reload_config()¶ Reload config from system variable. Look to system variable
LABELORD_CONFIGfor path to config file. Default isconfig.cfgReload whole authentication and all settings from configReturn type: None Returns: None Raises: SystemExit – if no webhook provided
-
set_labelord_config(config)¶ Setter for config (set ConfigParser object)
Parameters: config ( ConfigParser) – config objectReturn type: None Returns: None
-
-
labelord.server.check_allowed_repo(repo)¶ Check if repo is allowed in config
Parameters: repo ( str) – repository stringReturn type: boolReturns: True if allowed, False otherwise
-
labelord.server.check_signature(msg, secret, signature)¶ Check sha1 sum of GitHub request
Parameters: - msg (
str) – body message - secret (
str) – secret from config - signature (
str) – signature from GitHub header
Return type: boolReturns: True if checked, False otherwise
- msg (
-
labelord.server.convert_git_repo(text)¶ Create link to GitHub repo
-
labelord.server.create_label_request(js)¶ Handle POST request for create label Create new label
Parameters: js – json request object Return type: None Returns: None
-
labelord.server.delete_label_request(js)¶ Handle POST request for delete label Delete label
Parameters: js – json request object Return type: None Returns: None
-
labelord.server.edit_label_request(js)¶ Handle POST edit label :param js: json request object :return: None
-
labelord.server.index()¶ Main page of application Show main information about settings of server (repos, basic info..)
Return type: strReturns:
-
labelord.server.post_request()¶ Request handler for POST method This function handle all post requests to our page. Parse post request, control all authentication and call correct function from labelord
Return type: strReturns: str Raises: flaskAbort – if come request with bad header