Skip to content

Commit

Permalink
feat: repo projects
Browse files Browse the repository at this point in the history
  • Loading branch information
nedbat committed Mar 17, 2022
1 parent 80eb1e3 commit f697f29
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 35 deletions.
3 changes: 3 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ clause sets defaults for the digest options in the rest of the file. Each
- A URL to a repo's pull requests will report on the pull requests in the
repo.

- A URL to a repo project will report on the issues and pull requests in
the project.

- The ``pull_requests`` setting can specify an organization to search for
pull requests.

Expand Down
4 changes: 4 additions & 0 deletions scriv.d/20220316_210842_nedbat.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Added
.....

- Repo projects are supported.
44 changes: 39 additions & 5 deletions src/dinghy/digest.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,17 @@ async def get_repo_issues(self, owner, name):
}
return container

async def get_project_entries(self, org, number, home_repo=""):
async def get_org_project_entries(self, org, number, home_repo=""):
"""
Get entries from a project.
Get entries from a organization project.
Args:
org (str): the organization owner of the repo.
number (int|str): the project number.
home_repo (str): the owner/name of a repo that most entries are in.
"""
project, project_data = await self.gql.nodes(
query=build_query("project_entries.graphql"),
query=build_query("org_project_entries.graphql"),
variables=dict(org=org, projectNumber=int(number)),
)
entries = [content for data in project_data if (content := data["content"])]
Expand All @@ -86,6 +86,36 @@ async def get_project_entries(self, org, number, home_repo=""):
}
return container

async def get_repo_project_entries(self, owner, name, number):
"""
Get entries from a repo project.
Args:
owner (str): the owner of the repo.
name (str): the name of the repo.
number (int|str): the project number.
"""
project, project_data = await self.gql.nodes(
query=build_query("repo_project_entries.graphql"),
variables=dict(owner=owner, name=name, projectNumber=int(number)),
)
home_repo = f"{owner}/{name}"
entries = [content for data in project_data if (content := data["content"])]
entries = await self._process_entries(entries)
for entry in entries:
entry["other_repo"] = entry["repository"]["nameWithOwner"] != home_repo
if "comments_to_show" not in entry:
entry["comments_to_show"] = entry["comments"]["nodes"]
project = glom(project, "data.repository.project")
container = {
"url": project["url"],
"container_kind": "project",
"title": project["title"],
"kind": "items",
"entries": entries,
}
return container

async def get_repo_pull_requests(self, owner, name):
"""
Get pull requests from a repo updated since a date, with comments since that date.
Expand Down Expand Up @@ -164,6 +194,10 @@ def method_from_url(self, url):
A method, and a dict of **kwargs.
"""
for rx, fn in [
(
r"https://github.com/orgs/(?P<org>[^/]+)/projects/(?P<number>\d+)/?",
self.get_org_project_entries,
),
(
r"https://github.com/(?P<owner>[^/]+)/(?P<name>[^/]+)/issues/?",
self.get_repo_issues,
Expand All @@ -177,8 +211,8 @@ def method_from_url(self, url):
self.get_repo_entries,
),
(
r"https://github.com/orgs/(?P<org>[^/]+)/projects/(?P<number>\d+)/?",
self.get_project_entries,
r"https://github.com/(?P<owner>[^/]+)/(?P<name>[^/]+)/projects/(?P<number>\d+)/?",
self.get_repo_project_entries,
),
]:
if match_url := re.fullmatch(rx, url):
Expand Down
11 changes: 11 additions & 0 deletions src/dinghy/graphql/org_project_entries.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
query getOrgProjectItems(
$org: String!
$projectNumber: Int!
$after: String
) {
organization(login: $org) {
project: projectNext(number: $projectNumber) {
...projectNextData # fragment: project_entries_frag.graphql
}
}
}
28 changes: 0 additions & 28 deletions src/dinghy/graphql/project_entries.graphql

This file was deleted.

21 changes: 21 additions & 0 deletions src/dinghy/graphql/project_entries_frag.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# A project in an org or repo.
fragment projectNextData on ProjectNext {
title
url
items(first: 10, after: $after) {
pageInfo {
hasNextPage
endCursor
}
nodes {
content {
... on Issue {
...issueData # fragment: issue_frag.graphql
}
... on PullRequest {
...pullRequestData # fragment: pull_request_frag.graphql
}
}
}
}
}
2 changes: 1 addition & 1 deletion src/dinghy/graphql/repo_issues.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ query getRepoIssues(
$after: String
) {
repository(owner: $owner, name: $name) {
...repoData
...repoData # fragment: repo_frag.graphql
issues(
first: 100
filterBy: {
Expand Down
13 changes: 13 additions & 0 deletions src/dinghy/graphql/repo_project_entries.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
query getRepoProjectItems(
$owner: String!
$name: String!
$projectNumber: Int!
$after: String
) {
repository(owner: $owner, name: $name) {
...repoData # fragment: repo_frag.graphql
project: projectNext(number: $projectNumber) {
...projectNextData # fragment: project_entries_frag.graphql
}
}
}
2 changes: 1 addition & 1 deletion src/dinghy/graphql/repo_pull_requests.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ query getPullRequests(
$after: String
) {
repository(owner: $owner, name: $name) {
...repoData
...repoData # fragment: repo_frag.graphql
pullRequests(
first: 10
orderBy: {
Expand Down

0 comments on commit f697f29

Please sign in to comment.