Skip to content

Commit cc9bb6e

Browse files
authored
Merge pull request #270 from NASA-IMPACT/269-github-pipeline-shows-0-files-changed-even-with-rules-present
Fix bugs in the GitHub pipeline
2 parents 4ef93c8 + 06d3d5f commit cc9bb6e

File tree

4 files changed

+48
-26
lines changed

4 files changed

+48
-26
lines changed

sde_collections/management/commands/push_config_to_github

Lines changed: 0 additions & 24 deletions
This file was deleted.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from django.core.management.base import BaseCommand
2+
3+
from sde_collections.models.collection import Collection
4+
from sde_collections.utils.github_helper import GitHubHandler
5+
6+
7+
class Command(BaseCommand):
8+
help = (
9+
"Push config to github. Takes comma-separated config_folder list as argument."
10+
)
11+
12+
def add_arguments(self, parser):
13+
parser.add_argument("config_folders", nargs="*", type=str, default=[])
14+
15+
def handle(self, *args, **options):
16+
config_folders = options["config_folders"]
17+
18+
# curation status 5 is Curated
19+
collections = Collection.objects.filter(
20+
config_folder__in=config_folders
21+
).filter(curation_status=5)
22+
23+
cant_push = Collection.objects.filter(config_folder__in=config_folders).exclude(
24+
curation_status=5
25+
)
26+
cant_push = list(cant_push.values_list("name", flat=True))
27+
28+
gh = GitHubHandler(collections)
29+
gh.push_to_github()
30+
31+
self.stdout.write(
32+
self.style.SUCCESS(
33+
"Successfully pushed: %s"
34+
% list(collections.values_list("name", flat=True))
35+
)
36+
)
37+
38+
if cant_push:
39+
self.stdout.write(
40+
self.style.ERROR(
41+
"Can't push since status is not Curated (choice_id:5) %s"
42+
% cant_push
43+
)
44+
)

sde_collections/utils/github_helper.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,14 @@ def _update_file_contents(self, collection):
4040
"""
4141
contents = self._get_file_contents(collection)
4242
FILE_CONTENTS = contents.decoded_content.decode("utf-8")
43+
updated_xml = collection.update_config_xml(FILE_CONTENTS)
4344

4445
COMMIT_MESSAGE = f"Webapp: Update {collection.name}"
4546

4647
self.repo.update_file(
4748
contents.path,
4849
COMMIT_MESSAGE,
49-
FILE_CONTENTS,
50+
updated_xml,
5051
contents.sha,
5152
branch=self.github_branch,
5253
)
@@ -66,6 +67,7 @@ def create_pull_request(self):
6667

6768
def push_to_github(self):
6869
for collection in self.collections:
70+
print(f"Pushing {collection.name} to GitHub.")
6971
self._update_file_contents(collection)
7072
collection.curation_status = CurationStatusChoices.GITHUB_PR_CREATED
7173
collection.save()

sde_collections/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ def post(self, request):
292292
"collection_ids can't be empty.", status=status.HTTP_400_BAD_REQUEST
293293
)
294294

295-
push_to_github_task(collection_ids)
295+
push_to_github_task.delay(collection_ids)
296296

297297
return Response(
298298
{"Success": "Started pushing collections to github"},

0 commit comments

Comments
 (0)