Skip to content
This repository has been archived by the owner on Aug 25, 2024. It is now read-only.

Commit

Permalink
alice: please: contribute: recommended community standards: overlay: …
Browse files Browse the repository at this point in the history
…github: permissions checks: Refactor into seperate helper function which takes origin

Signed-off-by: John Andersen <[email protected]>
  • Loading branch information
pdxjohnny committed Jul 28, 2022
1 parent e9e43d6 commit d38955a
Showing 1 changed file with 38 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,32 @@


import dffml
from dffml_feature_git.feature.definitions import git_remote

from ....recommended_community_standards import AliceGitRepo, AlicePleaseContributeRecommendedCommunityStandards
from .pull_request import AlicePleaseContributeRecommendedCommunityStandardsOverlayGitHubPullRequest
from ....recommended_community_standards import (
AliceGitRepo,
AlicePleaseContributeRecommendedCommunityStandards,
)
from .pull_request import (
AlicePleaseContributeRecommendedCommunityStandardsOverlayGitHubPullRequest,
)


class AlicePleaseContributeRecommendedCommunityStandardsOverlayGitHubWritableRemotesFromPermissions:
async def already_owns_repo(
self, repo: AliceGitRepo,
) -> AlicePleaseContributeRecommendedCommunityStandardsOverlayGitHubPullRequest.WriteableGitRemoteOrigin:
if repo.URL is None:
return
origins = {}
async for event, result in dffml.run_command_events(
["git", "remote", "-v"],
cwd=repo.directory,
logger=self.logger,
events=[dffml.Subprocess.STDOUT_READLINE],
):
if event is dffml.Subprocess.STDOUT_READLINE:
origin, url_and_usages = result.decode().strip().split("\t", maxsplit=2)
origins[origin] = url_and_usages.split()[0]
for origin, url in origins.items():
async def github_owns_remote(
self, directory: str, check_remote: str, *, logger=None,
) -> bool:
remotes = {}
async for event, result in dffml.run_command_events(
["git", "remote", "-v"],
cwd=directory,
logger=logger,
events=[dffml.Subprocess.STDOUT_READLINE],
):
if event is dffml.Subprocess.STDOUT_READLINE:
remote, url_and_usages = result.decode().strip().split("\t", maxsplit=2)
if remote != check_remote:
continue
url = url_and_usages.split()[0]
async for event, result in dffml.run_command_events(
[
"gh",
Expand All @@ -46,12 +50,21 @@ async def already_owns_repo(
"-q",
".viewerPermission",
],
logger=self.logger,
logger=logger,
events=[dffml.Subprocess.STDOUT],
):
result = result.strip().decode()
if event is dffml.Subprocess.STDOUT and result in (
"ADMIN",
"MAINTAIN",
):
return origin
if event is dffml.Subprocess.STDOUT and result in ("ADMIN", "MAINTAIN"):
return True
return False


class AlicePleaseContributeRecommendedCommunityStandardsOverlayGitHubWritableRemotesFromPermissions:
async def github_owns_remote(
self, repo: AliceGitRepo, remote: git_remote,
) -> AlicePleaseContributeRecommendedCommunityStandardsOverlayGitHubPullRequest.WriteableGitRemoteOrigin:
if repo.URL is None or not await github_owns_remote(
self, repo.directory, remote, logger=self.logger
):
return
return remote

0 comments on commit d38955a

Please sign in to comment.