Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make workflows optional #36

Merged
merged 2 commits into from
Apr 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,11 @@ keys:
See "`Path Templates`_" for more information.

``workflows``
A list of the filenames for the workflows for which to retrieve
logs. The filenames should only consist of the workflow basenames,
including the file extension (e.g., ``test.yml``, not
``.github/workflows/test.yml``).
*(optional)* A list of the filenames for the workflows for which to
retrieve logs. The filenames should only consist of the workflow
basenames, including the file extension (e.g., ``test.yml``, not
``.github/workflows/test.yml``). When ``workflows`` is not
specified, logs are retrieved for all workflows in the repository.

``travis``
Configuration for retrieving logs from Travis-CI.com. Subfield:
Expand Down
24 changes: 18 additions & 6 deletions src/tinuous/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"failed": "failed",
"errored": "errored",
"timed_out": "errored",
"startup_failure": "errored",
"neutral": "incomplete",
"action_required": "incomplete",
"cancelled": "incomplete",
Expand Down Expand Up @@ -135,7 +136,7 @@ def download(self, path: Path) -> List[Path]:

@dataclass
class GitHubActions(CISystem):
workflows: List[str]
workflows: Optional[List[str]]

@staticmethod
def get_auth_token() -> str:
Expand Down Expand Up @@ -164,12 +165,18 @@ def dl_session(self) -> requests.Session:
s.headers["Authorization"] = f"token {self.token}"
return s

def get_workflows(self) -> Iterator[Workflow]:
repo = self.client.get_repo(self.repo)
if self.workflows is None:
yield from repo.get_workflows()
else:
for wffile in self.workflows:
yield repo.get_workflow(wffile)

def get_build_logs(self, event_types: List[EventType]) -> Iterator["GHABuildLog"]:
log.info("Fetching runs newer than %s", self.since)
repo = self.client.get_repo(self.repo)
for wffile in self.workflows:
wf = repo.get_workflow(wffile)
log.info("Fetching runs for workflow %s (%s)", wffile, wf.name)
for wf in self.get_workflows():
log.info("Fetching runs for workflow %s (%s)", wf.path, wf.name)
for run in wf.get_runs(): # type: ignore[call-arg]
# <https://github.com/PyGithub/PyGithub/pull/1857>
run_event = EventType.from_gh_event(run.event)
Expand Down Expand Up @@ -263,6 +270,11 @@ def download(self, path: Path) -> List[Path]:
path,
)
r = self.session.get(self.logs_url)
if r.status_code == 404:
# This can happen when a workflow failed to run due to, say, a
# syntax error.
log.error("Request for logs returned 404; skipping")
return []
r.raise_for_status()
try:
with BytesIO(r.content) as blob, ZipFile(blob) as zf:
Expand Down Expand Up @@ -582,7 +594,7 @@ def get_system(self, repo: str, since: datetime, token: str) -> CISystem:


class GitHubConfig(CIConfig):
workflows: List[str]
workflows: Optional[List[str]] = None

@staticmethod
def get_auth_token() -> str:
Expand Down