Source code for repomatic.github.sponsor
# Copyright Kevin Deldycke <[email protected]> and contributors.
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
"""Check if a GitHub user is a sponsor of another user or organization.
Uses the GitHub GraphQL API via the `gh` CLI to query sponsorship data, with
pagination for accounts that have more than 100 sponsors.
"""
from __future__ import annotations
import logging
from .gh import iter_graphql_nodes
TYPE_CHECKING = False
if TYPE_CHECKING:
from collections.abc import Iterator
SPONSORS_QUERY = """
query($owner: String!, $cursor: String) {
repositoryOwner(login: $owner) {
... on Sponsorable {
sponsorshipsAsMaintainer(first: 100, after: $cursor, includePrivate: true) {
pageInfo { hasNextPage endCursor }
nodes { sponsorEntity { ... on User { login } ... on Organization { login } } }
}
}
}
}
"""
"""GraphQL query for an account's sponsors, a user or an organization alike.
`repositoryOwner` resolves both kinds of account, and both implement the
`Sponsorable` interface, so one query covers either without a probe for the
kind first.
"""