PK!uhkira_setup/__init__.py# -*- coding: utf-8 -*- PK!kira_setup/api.py# -*- coding: utf-8 -*- import gitlab from gitlab.v4.objects import Project from kira_setup.logging import report_progress from kira_setup.pipelines import labels, merge_requests, project, protected def _get_project(context) -> Project: gl = gitlab.Gitlab( 'https://' + context.domain, context.token, timeout=10, ) return gl.projects.get(context.path[0]) def _start_pipeline(current_project: Project) -> None: pipeline = [ project.star, project.configure, project.push_rules, merge_requests.approvals, labels.create, protected.branches, protected.tags, ] for pipeline_item in pipeline: report_progress(pipeline_item)(current_project) # type: ignore def start_pipeline(context) -> None: """Main function to start the whole project-setup pipeline.""" current_project = _get_project(context) _start_pipeline(current_project) PK!c?^kira_setup/cli.py#!/usr/bin/env python # -*- coding: utf-8 -*- import argparse from kira_setup.api import start_pipeline def _create_parser() -> argparse.ArgumentParser: parser = argparse.ArgumentParser() parser.add_argument('path', help='Project group / name') parser.add_argument('-t', '--token', type=str, help='Auth token') parser.add_argument( '-d', '--domain', default='gitlab.com', type=str, help='GitLab domain address, change if you use custom installation', ) return parser def main() -> None: """Runs all pipeline actions.""" parser = _create_parser() args = parser.parse_args() start_pipeline(args) PK!?kira_setup/logging.py# -*- coding: utf-8 -*- from functools import wraps from termcolor import colored def report_progress(function): """Decorates a function to print its execution status.""" @wraps(function) def decorator(*args, **kwargs): try: function_result = function(*args, **kwargs) message = '{0} succeed'.format(function.__name__) print(colored(message, 'green')) # noqa: T001 return function_result except Exception as exc: message = '{0} failed due to exception: {1}'.format( function.__name__, exc, ) print(colored(message, 'red')) # noqa: T001 raise return decorator PK!uh kira_setup/pipelines/__init__.py# -*- coding: utf-8 -*- PK!o.jkira_setup/pipelines/labels.py# -*- coding: utf-8 -*- from gitlab.v4.objects import Project _LABELS = { 'bug': '#FF0000', 'feature': '#428BCA', 'documentation': '#69D100', 'research': '#5843AD', 'deadline:soft': '#AD4363', 'deadline:hard': '#D10069', 'deadline:miss': '#CC0033', 'validation:labels': '#A295D6', 'validation:stale': '#A295D6', 'validation:invalid': '#7F8C8D', 'notification:first': '#D1D100', 'notification:last': '#F0AD4E', } def _is_prioritized(label: str) -> bool: """ Tells if label is prioritized or not. >>> _is_prioritized('feature') True >>> _is_prioritized('deadline:miss') False """ return ':' not in label def create(project: Project) -> None: """ Creates all labels that are required for our projects. API: https://docs.gitlab.com/ee/api/labels.html """ for label, color in _LABELS.items(): project.labels.create({ 'name': label, 'color': color, 'priority': _is_prioritized(label), }) PK! &kira_setup/pipelines/merge_requests.py# -*- coding: utf-8 -*- from gitlab.v4.objects import Project def approvals(project: Project) -> None: """ Configures how approvals work for merge requests. API: https://docs.gitlab.com/ee/api/merge_request_approvals.html """ approvals = project.approvals.get() approvals.approvals_before_merge = 1 approvals.reset_approvals_on_push = True approvals.disable_overriding_approvers_per_merge_request = True approvals.save() PK!$kira_setup/pipelines/project.py# -*- coding: utf-8 -*- from gitlab.v4.objects import Project #: Enforces conventional commits, #: see https://github.com/wemake-services/kira-release regex = r'^(revert: )?(feat|fix|docs|refactor|chore)(\(.+\))?:.{1,50}refs #\d+' def star(project: Project) -> None: """ Stars the given project. API: https://docs.gitlab.com/ee/api/projects.html#star-a-project """ project.star() def configure(project: Project) -> None: """ Configures basic things for a new project. API: https://docs.gitlab.com/ee/api/projects.html#edit-project """ project.resolve_outdated_diff_discussions = True project.only_allow_merge_if_pipeline_succeeds = True project.only_allow_merge_if_all_discussions_are_resolved = True project.merge_method = 'ff' project.save() def push_rules(project: Project) -> None: """ Sets all required push rules for the project. API: https://docs.gitlab.com/ee/api/projects.html#push-rules-starter """ rules = project.pushrules.get() rules.deny_delete_tag = True rules.member_check = True rules.prevent_secrets = True rules.branch_name_regex = r'^issue-\d+$' rules.commit_message_regex = regex rules.save() PK!(!ᡯ!kira_setup/pipelines/protected.py# -*- coding: utf-8 -*- import gitlab from gitlab.v4.objects import Project def branches(project: Project) -> None: """ Creates protected branch rules. API: https://docs.gitlab.com/ee/api/protected_branches.html """ project.protectedbranches.create({ 'name': 'master', 'merge_access_level': gitlab.DEVELOPER_ACCESS, 'push_access_level': gitlab.MAINTAINER_ACCESS, }) def tags(project: Project) -> None: """ Creates protected tag rules. API: https://docs.gitlab.com/ee/api/protected_tags.html """ project.protectedtags.create({ 'name': 'v*', 'create_access_level': gitlab.MAINTAINER_ACCESS, }) PK!H!.2+kira_setup-0.1.0.dist-info/entry_points.txtN+I/N.,(),J-N-)-1LL<..PK!f00"kira_setup-0.1.0.dist-info/LICENSEMIT License Copyright (c) 2018 wemake.services Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. PK!HڽTU kira_setup-0.1.0.dist-info/WHEEL A н#Z;/"d&F[xzw@Zpy3Fv]\fi4WZ^EgM_-]#0(q7PK!H3飵] #kira_setup-0.1.0.dist-info/METADATAVms8_2mzJ[ k37A7F\I_+y6x#K>N@р*j'6iXƈ`ԔԸ_[VݘeqL&Sp@'9$!+i̔HT*v2]w"*%b|]XCEfL&I&[5\"x"&k&xˡ@'? IqA0 O4b<'EǯQvDd$T$$T5TM8n'4&a"vQsW~g%q1˃R>L*Yyo}԰H"yE/Q(th)\2voK&&2϶)h7 &1WyyY^m,⏋g;,-db ZQ7IH, j!uCH}\i$4matS?g4/ytN;Ήӏgz8t7WA9>Wz›7ig;sw4o/g +>k3]OAdu~ [٬QL&?n'{н9ݸ8^r#G;W}_!\~EcmGH3eJoR+WXكtͤ3yg'h/[1œETw'>Y֛TŒ2[z 37[>/-# 3KDV`RW˃TfQ$dC6*;?[LbмMQsb7ԙbS[ݱc4 l+A;/he*WD-\,j/3fHR)^a瑊FQ~b0RV>%-0͒ +$M\\f2;L; |zt:lvy6>vG=ra|,Iv=&gbB X;6d o.ħ"Soޤ8l׋`鈢a' <=%I5947y154V~gE], Ǡ)܌4bRPK!Hey}!kira_setup-0.1.0.dist-info/RECORDɒ@}} c h!PLAH4ۍQtDs_ ԤI JT.Ixso8*&uK 6,].yFSR&Sa@Wø*k K4]:b:$ [+!At(IбBڍ7]VIyJ6tVjA ˿sT,t(eGŎxֽtcV0S # KT͖X1H9 A#Ʒ&DZ|1:b3{MzvS^=ibu"5dxO]݄ݝJ+Ln@̶֌XȽRǾ].ei5