From 4919770105edf2a0e8195dc272ce35109af918f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Janusz=20=22Ivellios=22=20Kamie=C5=84ski?= Date: Tue, 17 Dec 2024 16:01:33 +0100 Subject: [PATCH] =?UTF-8?q?Dodane=20automatyczne=20tworzenie=20lub=20aktua?= =?UTF-8?q?lizacja=20branchy/commit=C3=B3w/Pull=20Request=C3=B3w=20dla=20z?= =?UTF-8?q?g=C5=82osze=C5=84=20nowej=20organizacji;=20formatowanie=20plik?= =?UTF-8?q?=C3=B3w=20blackiem;=20zmiana=20ko=C5=84c=C3=B3w=20linii=20CRLF?= =?UTF-8?q?=20na=20LF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/ISSUE_TEMPLATE/config.yml | 16 +-- .github/ISSUE_TEMPLATE/dodanieproduktu.yaml | 76 ++++++------ .github/scripts/cli.py | 78 ++++++++++++ .github/scripts/consts.py | 7 +- .github/scripts/git_managers.py | 129 ++++++++++++++++++++ .github/scripts/labels.py | 11 +- .github/scripts/organization.yaml.j2 | 18 +++ .github/scripts/parsers.py | 6 +- .github/scripts/process.py | 64 ---------- .github/scripts/pullers.py | 24 ++-- .github/scripts/renderers.py | 28 +++++ .github/scripts/requirements.txt | 2 + .github/scripts/validators.py | 59 +++++---- .github/workflows/nowa-organizacja.yaml | 102 ++++++++-------- 14 files changed, 423 insertions(+), 197 deletions(-) create mode 100644 .github/scripts/cli.py create mode 100644 .github/scripts/git_managers.py create mode 100644 .github/scripts/organization.yaml.j2 delete mode 100644 .github/scripts/process.py create mode 100644 .github/scripts/renderers.py diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml index 4bff899..e7b601c 100644 --- a/.github/ISSUE_TEMPLATE/config.yml +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -1,8 +1,8 @@ -blank_issues_enabled: true -contact_links: - - name: Usuwanie produktu - url: https://github.com/wyslijco/wyslijco.github.io/wiki - about: Zobacz, jak możesz usunąć produkt ze strony swojej organizacji w Wyślij.co - - name: Usuwanie organizacji - url: https://github.com/wyslijco/wyslijco.github.io/wiki - about: Zobacz, jak usunąć swoją organizację z Wyślij.co +blank_issues_enabled: true +contact_links: + - name: Usuwanie produktu + url: https://github.com/wyslijco/wyslijco.github.io/wiki + about: Zobacz, jak możesz usunąć produkt ze strony swojej organizacji w Wyślij.co + - name: Usuwanie organizacji + url: https://github.com/wyslijco/wyslijco.github.io/wiki + about: Zobacz, jak usunąć swoją organizację z Wyślij.co diff --git a/.github/ISSUE_TEMPLATE/dodanieproduktu.yaml b/.github/ISSUE_TEMPLATE/dodanieproduktu.yaml index c4bd976..b1d7f71 100644 --- a/.github/ISSUE_TEMPLATE/dodanieproduktu.yaml +++ b/.github/ISSUE_TEMPLATE/dodanieproduktu.yaml @@ -1,38 +1,38 @@ -name: Dodanie produktu -description: Dodaj produkt do strony swojej organizacji. -title: "[Dodanie produktu]" -labels: ["organizacje", "nowy-produkt"] -assignees: - - ivellios - -body: - - type: markdown - attributes: - value: | - Ten formularz pomoże Ci w dodaniu produktu do strony Twojej organizacji w Wyślij.co - - type: dropdown - id: nazwa_organizacji - attributes: - label: Twoja organizacja - options: - - Testowa - validations: - required: true - - type: input - id: nazwa - attributes: - label: Nazwa produktu - validations: - required: true - - type: input - id: opis - attributes: - label: Krótki opis produktu - validations: - required: false - - type: input - id: link - attributes: - label: Link do produktu w sklepie internetowym - validations: - required: true +name: Dodanie produktu +description: Dodaj produkt do strony swojej organizacji. +title: "[Dodanie produktu]" +labels: ["organizacje", "nowy-produkt"] +assignees: + - ivellios + +body: + - type: markdown + attributes: + value: | + Ten formularz pomoże Ci w dodaniu produktu do strony Twojej organizacji w Wyślij.co + - type: dropdown + id: nazwa_organizacji + attributes: + label: Twoja organizacja + options: + - Testowa + validations: + required: true + - type: input + id: nazwa + attributes: + label: Nazwa produktu + validations: + required: true + - type: input + id: opis + attributes: + label: Krótki opis produktu + validations: + required: false + - type: input + id: link + attributes: + label: Link do produktu w sklepie internetowym + validations: + required: true diff --git a/.github/scripts/cli.py b/.github/scripts/cli.py new file mode 100644 index 0000000..5b4d12a --- /dev/null +++ b/.github/scripts/cli.py @@ -0,0 +1,78 @@ +import json +import logging +import os + +from github import Auth, Github, Issue + +from consts import OrgFormSchemaIds, NEW_ORG_ISSUE_DEFAULT_TITLE, NEW_ORG_FORM_SCHEMA_FILENAME +from git_managers import create_organization_yaml_pr +from labels import Label +from parsers import GithubIssueFormDataParser +from pullers import KRSDataPuller +from utils import has_label +from validators import OrgValidator +from renderers import render_organization_yaml + +logging.basicConfig( + level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s" +) +logger = logging.getLogger(__file__) + +GITHUB_TOKEN = os.getenv("GITHUB_TOKEN") +GITHUB_REPOSITORY = os.getenv("GITHUB_REPOSITORY") + +auth = Auth.Token(GITHUB_TOKEN) +g = Github(auth=auth) +repo = g.get_repo(GITHUB_REPOSITORY) + + +def process_new_org_issue(issue: Issue, data: GithubIssueFormDataParser): + if has_label(issue, Label.AUTO_VERIFIED): + issue.remove_from_labels(Label.AUTO_VERIFIED) + + validator = OrgValidator(data, issue) + if not validator.validate(): + logger.error("Validation failed") + return + + if not (org := KRSDataPuller.get_org_by_krs(issue, data.get(OrgFormSchemaIds.krs))): + logger.error("KRS db validation failed") + return + + # Update issue title + if issue.title == NEW_ORG_ISSUE_DEFAULT_TITLE: + logger.info("Updating issue title") + issue.edit( + title=f"{NEW_ORG_ISSUE_DEFAULT_TITLE} {org.name or data.get(OrgFormSchemaIds.name)}" + ) + + logger.info("Adding auto-verified label") + if not has_label(issue, Label.WAITING): + issue.add_to_labels(Label.WAITING) + issue.create_comment( + f"@{issue.user.login}, dziękujemy za podanie informacji. " + f"Przyjęliśmy zgłoszenie dodania nowej organizacji. " + f"Wkrótce skontaktujemy się celem weryfikacji zgłoszenia." + ) + + # mark as verified + issue.add_to_labels(Label.AUTO_VERIFIED) + + # create organization yaml file and add to the Pull Request + yaml_string = render_organization_yaml(data) + create_organization_yaml_pr(issue, yaml_string, data) + + +def main(): + github_form_json = os.getenv("GITHUB_FORM_JSON") + github_issue_number = int(os.getenv("GITHUB_ISSUE_NUMBER")) + + issue = repo.get_issue(github_issue_number) + data = GithubIssueFormDataParser( + json.loads(github_form_json), NEW_ORG_FORM_SCHEMA_FILENAME + ) + process_new_org_issue(issue, data) + + +if __name__ == "__main__": + main() diff --git a/.github/scripts/consts.py b/.github/scripts/consts.py index b95d075..b58569e 100644 --- a/.github/scripts/consts.py +++ b/.github/scripts/consts.py @@ -1,9 +1,9 @@ import enum -class OrgSchemaIds(enum.StrEnum): +class OrgFormSchemaIds(enum.StrEnum): name = "nazwa" - www = "www" + website = "www" krs = "krs" slug = "nazwa_strony" street = "ulica" @@ -11,8 +11,9 @@ class OrgSchemaIds(enum.StrEnum): city = "miasto" phone_number = "telefon" + NEW_ORG_ISSUE_DEFAULT_TITLE = "[Nowa Organizacja]" -NEW_ORG_SCHEMA_FILENAME = "nowa.yaml" +NEW_ORG_FORM_SCHEMA_FILENAME = "nowa.yaml" ORG_SCHEMA_SLUG_FIELD = "adres" diff --git a/.github/scripts/git_managers.py b/.github/scripts/git_managers.py new file mode 100644 index 0000000..c080c33 --- /dev/null +++ b/.github/scripts/git_managers.py @@ -0,0 +1,129 @@ +import logging + +from github import GithubException, InputGitTreeElement +from github.GitCommit import GitCommit +from github.GitRef import GitRef +from github.Issue import Issue +from github.PullRequest import PullRequest +from github.Repository import Repository + +from consts import OrgFormSchemaIds +from parsers import GithubIssueFormDataParser + + +logger = logging.getLogger(__file__) + + +class GitManager: + """Manager for creating a new branch and pull request with a file commit in the repo.""" + + def __init__(self, repo: Repository): + self.repo = repo + + def commit_file_contents_to_branch( + self, branch_ref: GitRef, file_path: str, contents: str, commit_message: str + ) -> GitCommit: + latest_commit = self.repo.get_commit(branch_ref.object.sha) + blob = self.repo.create_git_blob(contents, "utf-8") + tree_element = InputGitTreeElement( + path=file_path, mode="100644", type="blob", sha=blob.sha + ) + base_tree = latest_commit.commit.tree + new_tree = self.repo.create_git_tree([tree_element], base_tree) + new_commit = self.repo.create_git_commit( + message=commit_message, tree=new_tree, parents=[latest_commit.commit] + ) + return new_commit + + def get_or_create_branch(self, source_branch: str, new_branch_name: str) -> GitRef: + try: + branch_ref = self.repo.get_git_ref(f"heads/{new_branch_name}") + print(f"Branch '{new_branch_name}' already exists.") + except GithubException as e: + if e.status == 404: + # Branch does not exist, create it from the source branch + source = self.repo.get_branch(source_branch) + self.repo.create_git_ref( + ref=f"refs/heads/{new_branch_name}", sha=source.commit.sha + ) + branch_ref = self.repo.get_git_ref(f"heads/{new_branch_name}") + print(f"Branch '{new_branch_name}' created from '{source_branch}'.") + else: + raise e + return branch_ref + + def get_or_create_pr( + self, target_branch: str, new_branch_name: str, pr_title: str, pr_body: str + ) -> PullRequest: + pulls = self.repo.get_pulls( + state="open", + head=f"{self.repo.owner.login}:{new_branch_name}", + base=target_branch, + ) + if pulls.totalCount > 0: + logger.warning( + f"Pull request already exists for branch '{new_branch_name}': {pulls[0].html_url}" + ) + return pulls[0] + else: + logger.info(f"Creating pull request for branch '{new_branch_name}'") + return self.repo.create_pull( + title=pr_title, body=pr_body, head=new_branch_name, base=target_branch + ) + + def create_or_update_remote_branch_with_file_commit( + self, + source_branch: str, + new_branch: str, + file_path: str, + file_contents: str, + commit_message: str, + ) -> GitRef: + """Create or update a remote branch with a file commit.""" + branch = self.get_or_create_branch(source_branch, new_branch) + commit = self.commit_file_contents_to_branch( + branch, file_path, file_contents, commit_message + ) + branch.edit(commit.sha) + return branch + + def create_or_update_pr_with_file( + self, + source_branch: str, + new_branch: str, + pr_title: str, + pr_body: str, + file_path: str, + file_contents: str, + commit_message: str, + ) -> PullRequest: + self.create_or_update_remote_branch_with_file_commit( + source_branch, new_branch, file_path, file_contents, commit_message + ) + return self.get_or_create_pr(source_branch, new_branch, pr_title, pr_body) + + +def create_organization_yaml_pr( + issue: Issue, yaml_string: str, data: GithubIssueFormDataParser +): + repo = issue.repository + + source_branch = "main" + new_branch_name = f"nowa-organizacja-zgloszenie-{issue.number}" + + commit_message = f"Dodana nowa organizacja: {data.get(OrgFormSchemaIds.name)} | Zgłoszenie: #{issue.number}" + pr_title = f"Dodana nowa organizacja: {data.get(OrgFormSchemaIds.name)} | Zgłoszenie: #{issue.number}" + pr_body = f"Automatycznie dodana nowa organizacja na podstawie zgłoszenia z issue #{issue.number}.\n\n Closes #{issue.number}" + + file_path = "organizations/organization.yaml" + + manager = GitManager(repo) + manager.create_or_update_pr_with_file( + source_branch=source_branch, + new_branch=new_branch_name, + pr_title=pr_title, + pr_body=pr_body, + file_path=file_path, + file_contents=yaml_string, + commit_message=commit_message, + ) diff --git a/.github/scripts/labels.py b/.github/scripts/labels.py index cff9c7d..eb8e5bd 100644 --- a/.github/scripts/labels.py +++ b/.github/scripts/labels.py @@ -1,6 +1,6 @@ import enum -from consts import OrgSchemaIds +from consts import OrgFormSchemaIds class Label(enum.StrEnum): @@ -9,11 +9,12 @@ class Label(enum.StrEnum): INVALID_PHONE = "niepoprawny numer telefonu" INVALID_SLUG = "niepoprawna nazwa strony" AUTO_VERIFIED = "zweryfikowana automatycznie" + WAITING = "oczekuje na akceptację" INVALID_FIELD_TO_LABEL = { - OrgSchemaIds.krs: Label.INVALID_KRS, - OrgSchemaIds.postal_code: Label.INVALID_POSTAL_CODE, - OrgSchemaIds.phone_number: Label.INVALID_PHONE, - OrgSchemaIds.slug: Label.INVALID_SLUG, + OrgFormSchemaIds.krs: Label.INVALID_KRS, + OrgFormSchemaIds.postal_code: Label.INVALID_POSTAL_CODE, + OrgFormSchemaIds.phone_number: Label.INVALID_PHONE, + OrgFormSchemaIds.slug: Label.INVALID_SLUG, } diff --git a/.github/scripts/organization.yaml.j2 b/.github/scripts/organization.yaml.j2 new file mode 100644 index 0000000..6fd42f5 --- /dev/null +++ b/.github/scripts/organization.yaml.j2 @@ -0,0 +1,18 @@ +nazwa: {{ organization.name }} + +# wyslij.co/testowej - adres, pod którym będzie dostępna strona +adres: {{ organization.slug }} + +strona: {{ organization.website }} +krs: {{ organization.krs }} + +dostawa: + ulica: {{ organization.street }} + kod: {{ organization.postal_code }} + miasto: {{ organization.city }} + telefon: {{ organization.phone_number }} + +produkty: + - nazwa: Testowy produkt + link: http://example.com + diff --git a/.github/scripts/parsers.py b/.github/scripts/parsers.py index 1d021a7..1bd142d 100644 --- a/.github/scripts/parsers.py +++ b/.github/scripts/parsers.py @@ -3,7 +3,11 @@ import yaml -class FormDataParser: +class GithubIssueFormDataParser: + """ + Parses data comming from a Github issue form converted + to a dictionary and provides methods to access the data + """ def __init__(self, form_data: dict[str, Any], form_schema_filename: str): self.form_data = form_data diff --git a/.github/scripts/process.py b/.github/scripts/process.py deleted file mode 100644 index 8410448..0000000 --- a/.github/scripts/process.py +++ /dev/null @@ -1,64 +0,0 @@ -import json -import logging -import os - -from github import Auth, Github, Issue - -from consts import OrgSchemaIds, NEW_ORG_ISSUE_DEFAULT_TITLE, NEW_ORG_SCHEMA_FILENAME -from labels import Label -from parsers import FormDataParser -from pullers import OrgDataPuller -from utils import has_label -from validators import OrgValidator - -logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') -logger = logging.getLogger(__file__) - -GITHUB_TOKEN = os.getenv("GITHUB_TOKEN") -GITHUB_REPOSITORY = os.getenv("GITHUB_REPOSITORY") - -auth = Auth.Token(GITHUB_TOKEN) -g = Github(auth=auth) -repo = g.get_repo(GITHUB_REPOSITORY) - - -def process_new_org_issue(issue: Issue, data: FormDataParser): - if has_label(issue, Label.AUTO_VERIFIED): - issue.remove_from_labels(Label.AUTO_VERIFIED) - - validator = OrgValidator(data, issue) - if not validator.validate(): - logger.error("Validation failed") - return - - if not (org := OrgDataPuller.get_org_by_krs(issue, data.get(OrgSchemaIds.krs))): - logger.error("KRS db validation failed") - return - - # Update issue title - if issue.title == NEW_ORG_ISSUE_DEFAULT_TITLE: - logger.info("Updating issue title") - issue.edit(title=f"{NEW_ORG_ISSUE_DEFAULT_TITLE} {org.name or data.get(OrgSchemaIds.name)}") - - if not has_label(issue, Label.AUTO_VERIFIED): - logger.info("Adding auto-verified label") - issue.create_comment(f"@{issue.user.login}, dziękujemy za podanie informacji. " - f"Przyjęliśmy zgłoszenie dodania nowej organizacji. " - f"Wkrótce skontaktujemy się celem weryfikacji zgłoszenia.") - issue.add_to_labels(Label.AUTO_VERIFIED) - - -def main(): - github_form_json = os.getenv("GITHUB_FORM_JSON") - github_issue_number = int(os.getenv("GITHUB_ISSUE_NUMBER")) - - issue = repo.get_issue(github_issue_number) - data = FormDataParser( - json.loads(github_form_json), - NEW_ORG_SCHEMA_FILENAME - ) - process_new_org_issue(issue, data) - - -if __name__ == "__main__": - main() diff --git a/.github/scripts/pullers.py b/.github/scripts/pullers.py index 1b31313..d9f7fea 100644 --- a/.github/scripts/pullers.py +++ b/.github/scripts/pullers.py @@ -8,14 +8,16 @@ from labels import Label -class OrgDataPuller: +class KRSDataPuller: def __init__(self, krs: str): self.krs = krs self.data = self.pull_data() def pull_data(self) -> dict | None: - response = requests.get(f"https://api-krs.ms.gov.pl/api/krs/OdpisAktualny/{self.krs}?rejestr=S&format=json") + response = requests.get( + f"https://api-krs.ms.gov.pl/api/krs/OdpisAktualny/{self.krs}?rejestr=S&format=json" + ) if response.status_code == 200: return response.json() else: @@ -23,17 +25,25 @@ def pull_data(self) -> dict | None: @property def name(self): - return self.data.get("odpis", {}).get("dane", {}).get("dzial1", {}).get("danePodmiotu", {}).get("nazwa") + return ( + self.data.get("odpis", {}) + .get("dane", {}) + .get("dzial1", {}) + .get("danePodmiotu", {}) + .get("nazwa") + ) @staticmethod - def get_org_by_krs(issue: Issue, krs: str) -> Optional["OrgDataPuller"]: + def get_org_by_krs(issue: Issue, krs: str) -> Optional["KRSDataPuller"]: # Downloading official org data try: - org = OrgDataPuller(krs) + org = KRSDataPuller(krs) except requests.HTTPError as e: - issue.create_comment(f"Nie udało się pobrać danych o organizacji z KRS. " - f"Proszę sprawdzić, czy podany numer jest poprawny") + issue.create_comment( + f"Nie udało się pobrać danych o organizacji z KRS. " + f"Proszę sprawdzić, czy podany numer jest poprawny" + ) issue.add_to_labels(Label.INVALID_KRS) return diff --git a/.github/scripts/renderers.py b/.github/scripts/renderers.py new file mode 100644 index 0000000..2022209 --- /dev/null +++ b/.github/scripts/renderers.py @@ -0,0 +1,28 @@ +import os + +from jinja2 import FileSystemLoader, Environment + +from consts import OrgFormSchemaIds +from parsers import GithubIssueFormDataParser + + +def render_organization_yaml(data: GithubIssueFormDataParser): + template_dir = os.path.dirname(os.path.abspath(__file__)) + env = Environment(loader=FileSystemLoader(template_dir)) + + template = env.get_template("organization.yaml.j2") + + fields = ( + "name", + "slug", + "website", + "krs", + "street", + "postal_code", + "city", + "phone_number", + ) + + org_data = {field: data.get(getattr(OrgFormSchemaIds, field)) for field in fields} + + return template.render(organization=org_data) diff --git a/.github/scripts/requirements.txt b/.github/scripts/requirements.txt index b1e69e0..2fe44d1 100644 --- a/.github/scripts/requirements.txt +++ b/.github/scripts/requirements.txt @@ -1,3 +1,5 @@ PyGithub==2.5.0 PyYAML==6.0.2 requests==2.32.3 +GitPython==3.1.43 +black==24.10.0 diff --git a/.github/scripts/validators.py b/.github/scripts/validators.py index f03f1e0..9dd958a 100644 --- a/.github/scripts/validators.py +++ b/.github/scripts/validators.py @@ -4,46 +4,56 @@ import yaml from github import Issue -from consts import OrgSchemaIds, ORG_SCHEMA_SLUG_FIELD +from consts import OrgFormSchemaIds, ORG_SCHEMA_SLUG_FIELD from labels import INVALID_FIELD_TO_LABEL -from parsers import FormDataParser +from parsers import GithubIssueFormDataParser from utils import has_label class OrgValidator: - def __init__(self, data: FormDataParser, issue: Issue): + def __init__(self, data: GithubIssueFormDataParser, issue: Issue): self.data = data self.issue = issue def validate_krs(self) -> tuple[bool, str]: - return bool(re.fullmatch(r"\d{10}", self.data.get(OrgSchemaIds.krs))), "niepoprawny numer KRS" + return ( + bool(re.fullmatch(r"\d{10}", self.data.get(OrgFormSchemaIds.krs))), + "niepoprawny numer KRS", + ) def validate_postal_code(self) -> tuple[bool, str]: - return bool( - re.fullmatch(r"\d{2}-\d{3}", self.data.get(OrgSchemaIds.postal_code)) - ), "niepoprawny kod pocztowy" + return ( + bool(re.fullmatch(r"\d{2}-\d{3}", self.data.get(OrgFormSchemaIds.postal_code))), + "niepoprawny kod pocztowy", + ) def validate_phone_number(self) -> tuple[bool, str]: - return bool( - re.fullmatch( - r"(\+?48|0048)?\d{9}", - re.sub(r"[\s-]", "", self.data.get(OrgSchemaIds.phone_number)) - ) - ), "niepoprawny numer telefonu" + return ( + bool( + re.fullmatch( + r"(\+?48|0048)?\d{9}", + re.sub(r"[\s-]", "", self.data.get(OrgFormSchemaIds.phone_number)), + ) + ), + "niepoprawny numer telefonu", + ) def validate_slug(self) -> tuple[bool, str]: """ Checks if any organization with the same slug already exists. """ - slug_value = self.data.get(OrgSchemaIds.slug) + slug_value = self.data.get(OrgFormSchemaIds.slug) for root, _, files in os.walk("../../organizations"): for file_name in files: with open(os.path.join(root, file_name), "r") as f: org_data = yaml.safe_load(f) if org_data[ORG_SCHEMA_SLUG_FIELD] == slug_value: - return False, f"organizacja z adresem `/{slug_value}` już istnieje w `wyślij.co`. Proszę zmienić wartość na inną." + return ( + False, + f"organizacja z adresem `/{slug_value}` już istnieje w `wyślij.co`. Proszę zmienić wartość na inną.", + ) return True, "" @@ -56,10 +66,10 @@ def validate(self) -> bool: """ validation_map = { - OrgSchemaIds.krs: self.validate_krs, - OrgSchemaIds.postal_code: self.validate_postal_code, - OrgSchemaIds.phone_number: self.validate_phone_number, - OrgSchemaIds.slug: self.validate_slug, + OrgFormSchemaIds.krs: self.validate_krs, + OrgFormSchemaIds.postal_code: self.validate_postal_code, + OrgFormSchemaIds.phone_number: self.validate_phone_number, + OrgFormSchemaIds.slug: self.validate_slug, } errors = [] @@ -71,10 +81,17 @@ def validate(self) -> bool: self.issue.remove_from_labels(label) else: self.issue.add_to_labels(label) - errors.append((field, msg,)) + errors.append( + ( + field, + msg, + ) + ) if errors: - msg = "Wprowadzone dane są nieprawidłowe. Prosimy o wprowadzenie poprawek:\n" + msg = ( + "Wprowadzone dane są nieprawidłowe. Prosimy o wprowadzenie poprawek:\n" + ) for field, error in errors: msg += f"- **{self.data.get_label(field)}**: {error}\n" self.issue.create_comment(msg) diff --git a/.github/workflows/nowa-organizacja.yaml b/.github/workflows/nowa-organizacja.yaml index 6f7807d..e43820b 100644 --- a/.github/workflows/nowa-organizacja.yaml +++ b/.github/workflows/nowa-organizacja.yaml @@ -1,50 +1,52 @@ -name: Przetwarzenie zgłoszenia organizacji - -on: - issues: - types: [opened, edited] - - -env: - GITHUB_TOKEN: ${{ github.token }} - -permissions: - contents: read - issues: write - -jobs: - - validate-form: - if: contains(github.event.issue.labels.*.name, 'nowa-organizacja') - name: Ekstrakcja danych z formularza - runs-on: ubuntu-latest - outputs: - payload: ${{ steps.parse.outputs.payload }} - steps: - - name: Parsowanie treści zgłoszenia - id: parse - uses: onmax/issue-form-parser@v1.5 - with: - issue_number: ${{ github.event.issue.number }} - - processing: - if: contains(github.event.issue.labels.*.name, 'nowa-organizacja') - needs: [validate-form] - name: Przetwarzenie zgłoszenia - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-python@v5 - with: - python-version: '3.12' - cache: 'pip' # caching pip dependencies - - name: Install dependencies - working-directory: ./.github/scripts - run: pip install -r requirements.txt - - name: Run script - env: - GITHUB_ISSUE_NUMBER: ${{ github.event.issue.number }} - GITHUB_FORM_JSON: ${{ needs.validate-form.outputs.payload }} - GITHUB_REPOSITORY: ${{ github.repository }} - working-directory: ./.github/scripts - run: python process.py +name: Przetwarzenie zgłoszenia organizacji + +on: + issues: + types: [opened, edited] + + +env: + GITHUB_TOKEN: ${{ github.token }} + +permissions: + contents: read + issues: write + pull-requests: write + +jobs: + + validate-form: + if: contains(github.event.issue.labels.*.name, 'nowa-organizacja') + name: Ekstrakcja danych z formularza + runs-on: ubuntu-latest + outputs: + payload: ${{ steps.parse.outputs.payload }} + steps: + - name: Parsowanie treści zgłoszenia + id: parse + uses: onmax/issue-form-parser@v1.5 + with: + issue_number: ${{ github.event.issue.number }} + + processing: + if: contains(github.event.issue.labels.*.name, 'nowa-organizacja') + needs: [validate-form] + name: Przetwarzenie zgłoszenia + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: '3.12' + cache: 'pip' # caching pip dependencies + - name: Install dependencies + working-directory: ./.github/scripts + run: pip install -r requirements.txt + - name: Run script + env: + GITHUB_ISSUE_NUMBER: ${{ github.event.issue.number }} + GITHUB_FORM_JSON: ${{ needs.validate-form.outputs.payload }} + GITHUB_REPOSITORY: ${{ github.repository }} + working-directory: ./.github/scripts + run: python cli.py +