1313
1414
1515import dffml
16+ from dffml_feature_git .feature .definitions import git_remote
1617
17- from ....recommended_community_standards import AliceGitRepo , AlicePleaseContributeRecommendedCommunityStandards
18- from .pull_request import AlicePleaseContributeRecommendedCommunityStandardsOverlayGitHubPullRequest
18+ from ....recommended_community_standards import (
19+ AliceGitRepo ,
20+ AlicePleaseContributeRecommendedCommunityStandards ,
21+ )
22+ from .pull_request import (
23+ AlicePleaseContributeRecommendedCommunityStandardsOverlayGitHubPullRequest ,
24+ )
1925
2026
21- class AlicePleaseContributeRecommendedCommunityStandardsOverlayGitHubWritableRemotesFromPermissions :
22- async def already_owns_repo (
23- self , repo : AliceGitRepo ,
24- ) -> AlicePleaseContributeRecommendedCommunityStandardsOverlayGitHubPullRequest .WriteableGitRemoteOrigin :
25- if repo .URL is None :
26- return
27- origins = {}
28- async for event , result in dffml .run_command_events (
29- ["git" , "remote" , "-v" ],
30- cwd = repo .directory ,
31- logger = self .logger ,
32- events = [dffml .Subprocess .STDOUT_READLINE ],
33- ):
34- if event is dffml .Subprocess .STDOUT_READLINE :
35- origin , url_and_usages = result .decode ().strip ().split ("\t " , maxsplit = 2 )
36- origins [origin ] = url_and_usages .split ()[0 ]
37- for origin , url in origins .items ():
27+ async def github_owns_remote (
28+ self , directory : str , check_remote : str , * , logger = None ,
29+ ) -> bool :
30+ remotes = {}
31+ async for event , result in dffml .run_command_events (
32+ ["git" , "remote" , "-v" ],
33+ cwd = directory ,
34+ logger = logger ,
35+ events = [dffml .Subprocess .STDOUT_READLINE ],
36+ ):
37+ if event is dffml .Subprocess .STDOUT_READLINE :
38+ remote , url_and_usages = result .decode ().strip ().split ("\t " , maxsplit = 2 )
39+ if remote != check_remote :
40+ continue
41+ url = url_and_usages .split ()[0 ]
3842 async for event , result in dffml .run_command_events (
3943 [
4044 "gh" ,
@@ -46,12 +50,21 @@ async def already_owns_repo(
4650 "-q" ,
4751 ".viewerPermission" ,
4852 ],
49- logger = self . logger ,
53+ logger = logger ,
5054 events = [dffml .Subprocess .STDOUT ],
5155 ):
5256 result = result .strip ().decode ()
53- if event is dffml .Subprocess .STDOUT and result in (
54- "ADMIN" ,
55- "MAINTAIN" ,
56- ):
57- return origin
57+ if event is dffml .Subprocess .STDOUT and result in ("ADMIN" , "MAINTAIN" ):
58+ return True
59+ return False
60+
61+
62+ class AlicePleaseContributeRecommendedCommunityStandardsOverlayGitHubWritableRemotesFromPermissions :
63+ async def github_owns_remote (
64+ self , repo : AliceGitRepo , remote : git_remote ,
65+ ) -> AlicePleaseContributeRecommendedCommunityStandardsOverlayGitHubPullRequest .WriteableGitRemoteOrigin :
66+ if repo .URL is None or not await github_owns_remote (
67+ self , repo .directory , remote , logger = self .logger
68+ ):
69+ return
70+ return remote
0 commit comments