GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — python/danger_python/danger.py at master · databank-startup/python Expand file tree/ Copy pathdanger.pyMore file actions 117 lines (87 loc) · 3.12 KB / Copy pathdanger.pyFile metadata and controls117 lines (87 loc) · 3.12 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 import json import sys from functools import partial from operator import attrgetter from typing import Any, Callable, Dict, List, Optional from pydantic import BaseModel from .models import ( BitBucketCloudJSONDSL, BitBucketServerJSONDSL, DangerDSLJSONType, DangerDSLJSONTypeSettings, GitHubDSL, GitJSONDSL, GitLabDSL, ) class Violation(BaseModel): message: str file_name: Optional[str] = None line: Optional[int] = None class Config: allow_population_by_field_name = True fields = {"message": "message", "file_name": "file", "line": "line"} class DangerMeta(BaseModel): href: str = "https://danger.systems/python" name: str = "danger-python" class Config: fields = {"href": "runtimeHref", "name": "runtimeName"} class DangerResults(BaseModel): fails: List[Violation] = [] warnings: List[Violation] = [] messages: List[Violation] = [] markdowns: List[Violation] = [] meta: DangerMeta = DangerMeta() def serialize_violation(violation: Violation) -> Dict[str, Any]: return violation.dict(exclude_none=True, by_alias=True) def serialize_results(results: DangerResults) -> Dict[str, Any]: return results.dict(exclude_none=True, by_alias=True) def load_dsl() -> DangerDSLJSONType: file_url = sys.stdin.read().split("danger://dsl/")[-1] with open(file_url, "r") as json_file: input_json = json.loads(json_file.read()) return DangerDSLJSONType(**input_json["danger"]) class Danger: def __init__(self): if not Danger.dsl: Danger.dsl = load_dsl() if not Danger.results: Danger.results = DangerResults() dsl: Optional[DangerDSLJSONType] = None results: Optional[DangerResults] = None @property def git(self) -> Optional[GitJSONDSL]: assert Danger.dsl is not None return Danger.dsl.git @property def github(self) -> Optional[GitHubDSL]: assert Danger.dsl is not None return Danger.dsl.github @property def bitbucket_cloud(self) -> Optional[BitBucketCloudJSONDSL]: assert Danger.dsl is not None return Danger.dsl.bitbucket_cloud @property def bitbucket_server(self) -> Optional[BitBucketServerJSONDSL]: assert Danger.dsl is not None return Danger.dsl.bitbucket_server @property def gitlab(self) -> Optional[GitLabDSL]: assert Danger.dsl is not None return Danger.dsl.gitlab @property def settings(self) -> Optional[DangerDSLJSONTypeSettings]: assert Danger.dsl is not None return Danger.dsl.settings def _add_to_results( field: Callable[[DangerResults], List[Violation]], message: str, file_name: Optional[str] = None, line: Optional[int] = None, ): assert Danger.results is not None violation = Violation(message=message, file_name=file_name, line=line) field(Danger.results).append(violation) message = partial(_add_to_results, attrgetter("messages")) markdown = partial(_add_to_results, attrgetter("markdowns")) warn = partial(_add_to_results, attrgetter("warnings")) fail = partial(_add_to_results, attrgetter("fails")) |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |