@@ -88,6 +88,7 @@ class AlicePleaseContributeCLIConfig:
88
88
class AlicePleaseContributeRecommendedCommunityStandards :
89
89
# TODO SystemContext __new__ auto populate config to have upstream set to
90
90
# dataflow generated from methods in this class with memory orchestarator.
91
+ ReadmePath = NewType ("ReadmePath" , object )
91
92
RepoString = NewType ("repo.string" , str )
92
93
ReadmeContents = NewType ("repo.directory.readme.contents" , str )
93
94
HasReadme = NewType ("repo.directory.readme.exists" , bool )
@@ -108,28 +109,27 @@ async def guess_repo_string_is_directory(
108
109
return
109
110
return AliceGitRepo (directory = repo_string , URL = None )
110
111
111
- def has_readme (self , repo : AliceGitRepo ,) -> "HasReadme" :
112
- return pathlib .Path (repo .directory , "README.md" ).exists ()
113
-
114
112
# TODO Run this system context where readme contexts is given on CLI or
115
113
# overriden via disabling of static overlay and application of overlay to
116
114
# generate contents dynamiclly.
117
- def create_readme_file (
115
+ def create_readme_file_if_not_exists (
118
116
self ,
119
117
repo : AliceGitRepo ,
120
- has_readme : "HasReadme" ,
121
118
readme_contents : Optional ["ReadmeContents" ] = "# My Awesome Project's README" ,
122
- ):
119
+ ) -> "ReadmePath" :
123
120
# Do not create readme if it already exists
124
- if has_readme :
125
- return
126
- pathlib .Path (repo .directory , "README.md" ).write_text (readme_contents )
121
+ path = pathlib .Path (repo .directory , "README.md" )
122
+ if path .exists ():
123
+ return path
124
+ path .write_text (readme_contents )
125
+ return path
127
126
128
127
129
128
# An overlay which could be installed if you have dffml-feature-git
130
129
# (aka dffml-operations-git) installed.
131
130
class AlicePleaseContributeRecommendedCommunityStandardsOverlayOperationsGit :
132
131
GuessedGitURL = NewType ("guessed.git.url" , bool )
132
+ DefaultBranchName = NewType ("default.branch.name" , str )
133
133
134
134
# The operations we use defined elsewhere
135
135
check_if_valid_git_repository_URL = (
@@ -140,6 +140,25 @@ class AlicePleaseContributeRecommendedCommunityStandardsOverlayOperationsGit:
140
140
dffml_feature_git .feature .operations .git_repo_default_branch
141
141
)
142
142
143
+ async def create_branch_if_none_exists (
144
+ self , repo : AliceGitRepo , name : Optional ["DefaultBranchName" ] = "main" ,
145
+ ) -> dffml_feature_git .feature .definitions .GitBranchType :
146
+ """
147
+ If there are no branches, the git_repo_default_branch operation will
148
+ return None, aka there si no default branch. Therefore, in this
149
+ operation, we check if there are any branches at all, and if there are
150
+ not we create a new branch. We could optionally facilitate interaction
151
+ of multiple similar operations which wish to create a default branch if
152
+ none exist by creating a new defintion which is locked which could be
153
+ used to synchronise communication aka request for lock from some service
154
+ which has no native locking (transmistion of NFT via DIDs over abitrary
155
+ channels for example).
156
+ """
157
+ await dffml .run_command (
158
+ ["git" , "branch" , "-M" , name ], cwd = repo .directory , logger = self .logger ,
159
+ )
160
+ return name
161
+
143
162
def guess_repo_string_is_url (
144
163
self ,
145
164
repo_string : AlicePleaseContributeRecommendedCommunityStandards .RepoString ,
@@ -160,6 +179,8 @@ def guessed_repo_string_is_operations_git_url(
160
179
) -> dffml_feature_git .feature .definitions .URLType :
161
180
return repo_url
162
181
182
+
183
+ class AlicePleaseContributeRecommendedCommunityStandardsOverlayAliceOperationsGit :
163
184
def git_repo_to_alice_git_repo (
164
185
repo : dffml_feature_git .feature .definitions .git_repository ,
165
186
) -> AliceGitRepo :
@@ -303,7 +324,6 @@ class AlicePleaseContributeRecommendedCommunityStandardsOverlayGitHubIssue:
303
324
304
325
"""
305
326
306
- ReadmePath = NewType ("ReadmePath" , str )
307
327
ReadmeIssue = NewType ("ReadmeIssue" , str )
308
328
ReadmeIssueTitle = NewType ("ReadmeIssueTitle" , str )
309
329
ReadmeIssueBody = NewType ("ReadmeIssueBody" , str )
@@ -350,11 +370,13 @@ def readme_commit_message(
350
370
"""
351
371
).lstrip ()
352
372
373
+ # TODO(alice) There is a bug with Optional which can be revield by use here
353
374
@staticmethod
354
375
def meta_issue_body (
355
376
repo : AliceGitRepo ,
377
+ base : AlicePleaseContributeRecommendedCommunityStandardsOverlayGit .BaseBranch ,
378
+ readme_path : AlicePleaseContributeRecommendedCommunityStandards .ReadmePath ,
356
379
readme_issue : Optional ["ReadmeIssue" ] = None ,
357
- readme_path : Optional ["ReadmePath" ] = None ,
358
380
) -> "MetaIssueBody" :
359
381
"""
360
382
>>> AlicePleaseContributeRecommendedCommunityStandardsGitHubIssueOverlay.meta_issue_body(
@@ -369,8 +391,8 @@ def meta_issue_body(
369
391
"""
370
392
return "\n " .join (
371
393
[
372
- "- [x] [README]({repo.URL}/blob/{base}/{readme_path.relative_to(repo.directory).as_posix()})"
373
- if readme_path is not None
394
+ f "- [x] [README]({ repo .URL } /blob/{ base } /{ readme_path .relative_to (repo .directory ).as_posix ()} )"
395
+ if readme_issue is None
374
396
else f"- [ ] { readme_issue } " ,
375
397
]
376
398
)
@@ -456,6 +478,7 @@ async def readme_pr(
456
478
AlicePleaseContributeRecommendedCommunityStandards ,
457
479
AlicePleaseContributeRecommendedCommunityStandardsOverlayGit ,
458
480
AlicePleaseContributeRecommendedCommunityStandardsOverlayOperationsGit ,
481
+ AlicePleaseContributeRecommendedCommunityStandardsOverlayAliceOperationsGit ,
459
482
AlicePleaseContributeRecommendedCommunityStandardsOverlayCLI ,
460
483
AlicePleaseContributeRecommendedCommunityStandardsOverlayGitHubIssue ,
461
484
AlicePleaseContributeRecommendedCommunityStandardsOverlayGitHubPullRequest ,
0 commit comments