Skip to content

Commit

Permalink
Merge pull request #270 from NASA-IMPACT/269-github-pipeline-shows-0-…
Browse files Browse the repository at this point in the history
…files-changed-even-with-rules-present

Fix bugs in the GitHub pipeline
  • Loading branch information
code-geek authored Jun 16, 2023
2 parents 4ef93c8 + 06d3d5f commit cc9bb6e
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 26 deletions.
24 changes: 0 additions & 24 deletions sde_collections/management/commands/push_config_to_github

This file was deleted.

44 changes: 44 additions & 0 deletions sde_collections/management/commands/push_to_github.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from django.core.management.base import BaseCommand

from sde_collections.models.collection import Collection
from sde_collections.utils.github_helper import GitHubHandler


class Command(BaseCommand):
help = (
"Push config to github. Takes comma-separated config_folder list as argument."
)

def add_arguments(self, parser):
parser.add_argument("config_folders", nargs="*", type=str, default=[])

def handle(self, *args, **options):
config_folders = options["config_folders"]

# curation status 5 is Curated
collections = Collection.objects.filter(
config_folder__in=config_folders
).filter(curation_status=5)

cant_push = Collection.objects.filter(config_folder__in=config_folders).exclude(
curation_status=5
)
cant_push = list(cant_push.values_list("name", flat=True))

gh = GitHubHandler(collections)
gh.push_to_github()

self.stdout.write(
self.style.SUCCESS(
"Successfully pushed: %s"
% list(collections.values_list("name", flat=True))
)
)

if cant_push:
self.stdout.write(
self.style.ERROR(
"Can't push since status is not Curated (choice_id:5) %s"
% cant_push
)
)
4 changes: 3 additions & 1 deletion sde_collections/utils/github_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,14 @@ def _update_file_contents(self, collection):
"""
contents = self._get_file_contents(collection)
FILE_CONTENTS = contents.decoded_content.decode("utf-8")
updated_xml = collection.update_config_xml(FILE_CONTENTS)

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

self.repo.update_file(
contents.path,
COMMIT_MESSAGE,
FILE_CONTENTS,
updated_xml,
contents.sha,
branch=self.github_branch,
)
Expand All @@ -66,6 +67,7 @@ def create_pull_request(self):

def push_to_github(self):
for collection in self.collections:
print(f"Pushing {collection.name} to GitHub.")
self._update_file_contents(collection)
collection.curation_status = CurationStatusChoices.GITHUB_PR_CREATED
collection.save()
Expand Down
2 changes: 1 addition & 1 deletion sde_collections/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ def post(self, request):
"collection_ids can't be empty.", status=status.HTTP_400_BAD_REQUEST
)

push_to_github_task(collection_ids)
push_to_github_task.delay(collection_ids)

return Response(
{"Success": "Started pushing collections to github"},
Expand Down

0 comments on commit cc9bb6e

Please sign in to comment.