Skip to content

Commit

Permalink
fix+refactor: improve github monitoring workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgrittner committed Oct 14, 2024
1 parent 758d0d2 commit 0c545f7
Show file tree
Hide file tree
Showing 7 changed files with 291 additions and 55 deletions.
2 changes: 2 additions & 0 deletions admyral/actions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
list_google_docs_revisions,
list_ms_intune_unencrypted_managed_devices,
list_ms_intune_managed_devices,
list_github_issue_comments,
)
from admyral.actions.integrations.cloud import (
steampipe_query_aws,
Expand Down Expand Up @@ -153,4 +154,5 @@
"send_to_workflow",
"send_list_elements_to_workflow",
"split_text",
"list_github_issue_comments",
]
2 changes: 2 additions & 0 deletions admyral/actions/integrations/compliance/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
list_github_review_history_for_pull_request,
compare_two_github_commits,
list_github_merged_pull_requests_without_approval,
list_github_issue_comments,
)
from admyral.actions.integrations.compliance.google_drive import (
list_google_docs_revisions,
Expand All @@ -34,4 +35,5 @@
"list_google_docs_revisions",
"list_ms_intune_managed_devices",
"list_ms_intune_unencrypted_managed_devices",
"list_github_issue_comments",
]
59 changes: 53 additions & 6 deletions admyral/actions/integrations/compliance/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def _get_events_with_pagination(
else:
break

return events
return events if limit is None else events[:limit]


@action(
Expand Down Expand Up @@ -336,9 +336,9 @@ def list_github_commit_history_for_pull_request(


@action(
display_name="Get Approval History for a Pull Request",
display_name="List Review History for a Pull Request",
display_namespace="GitHub",
description="List approval history for a Pull Request",
description="List review history for a pull request.",
secrets_placeholders=["GITHUB_SECRET"],
)
def list_github_review_history_for_pull_request(
Expand Down Expand Up @@ -367,7 +367,7 @@ def list_github_review_history_for_pull_request(
Literal["APPROVED", "CHANGES_REQUESTED", "COMMENTED", "DISMISSED"] | None,
ArgumentMetadata(
display_name="State",
description="The state of the reviews to list.",
description="The state of the review to list.",
),
] = None,
) -> list[dict[str, JsonValue]]:
Expand Down Expand Up @@ -468,7 +468,7 @@ def list_github_merged_pull_requests_without_approval(
"title": pr["title"],
"html_url": pr["html_url"],
"user": pr["user"]["login"],
"closed_at": pr["closed_at"],
"merged_at": pr["merged_at"],
"last_commit_id": last_commit_id,
"last_approved_commit_id": pr["base"]["sha"],
}
Expand All @@ -489,10 +489,57 @@ def list_github_merged_pull_requests_without_approval(
"title": pr["title"],
"html_url": pr["html_url"],
"user": pr["user"]["login"],
"closed_at": pr["closed_at"],
"merged_at": pr["merged_at"],
"last_commit_id": last_commit_id,
"last_approved_commit_id": last_approved_commit_id,
}
)

return unreviewed_prs


@action(
display_name="Get Pull Request Comments",
display_namespace="GitHub",
description="Get comments for a pull request.",
secrets_placeholders=["GITHUB_SECRET"],
)
def list_github_issue_comments(
repo_owner: Annotated[
str,
ArgumentMetadata(
display_name="Repository Owner",
description="The owner of the repository",
),
],
repo_name: Annotated[
str,
ArgumentMetadata(
display_name="Repository Name",
description="The name of the repository",
),
],
number: Annotated[
int,
ArgumentMetadata(
display_name="Pull Request/Issue Number",
description="The number of the pull request or issue",
),
],
) -> list[dict[str, JsonValue]]:
# https://docs.github.com/en/rest/issues/comments?apiVersion=2022-11-28#list-issue-comments
secret = ctx.get().secrets.get("GITHUB_SECRET")
access_token = secret["access_token"]

with get_github_client(access_token=access_token) as client:
params = {
"per_page": 100,
}

events = _get_events_with_pagination(
client=client,
url=f"/repos/{repo_owner}/{repo_name}/issues/{number}/comments",
params=params,
)

return events
59 changes: 59 additions & 0 deletions docs/pages/integrations/github/apis/list_issue_comments.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { Callout } from "nextra/components";

# List Issue Comments

This method liss all comments of a pull request or issue in a GitHub repository.

<Callout type="info">
For more information on the API for listing pull requests, see [List issue
comments](https://docs.github.com/en/rest/issues/comments?apiVersion=2022-11-28#list-issue-comments).
</Callout>

To use this API endpoint for a private repository, your GitHub token requires the following scopes:

For a Fine-grained token:

```
- "Pull requests" repository permissions (read)
```

Alternatively, for a Token (classic):

```
- repo
```

**SDK Import:**

```python
from admyral.actions import list_github_issue_comments
```

## Arguments

| Argument Name | Description | Required |
| -------------------------------------- | ------------------------------------------------- | :------: |
| **Repository Owner** `repo_owner` | The owner of the repository. | yes |
| **Repository Name** `repo_name` | The name of the repository. | yes |
| **Pull Request/Issue Number** `number` | The number identifying the pull request or issue. | - |

## Returns

A JSON array of issue comments.

## Required Secrets

| Secret Placeholder | Description |
| ------------------ | -------------------------------------------------------------- |
| `GITHUB_SECRET` | GitHub secret. See [GitHub setup](/integrations/github/github) |

## SDK Example

```python
commit_diff = list_github_issue_comments(
repo_owner="admyral",
repo_name="admyral",
number=9,
secrets={"GITHUB_SECRET": "your_github_secret"}
)
```
Loading

0 comments on commit 0c545f7

Please sign in to comment.