Conversation
| URLS = {"contents": "/repos/{}/contents/{}", "repos": "/repos/{}"} | ||
|
|
||
|
|
||
| class Github_Interface: |
There was a problem hiding this comment.
Please rename class to GithubInterface
| return None | ||
| return response.json() | ||
|
|
||
| def return_github_url(self, url): |
There was a problem hiding this comment.
rename the method to get_github_url
| url = "{0}{1}".format(base_url, url) | ||
| return url | ||
|
|
||
| def get_content_from_path(self, path): |
There was a problem hiding this comment.
Please add docstring for this method
| return response | ||
|
|
||
| def get_data_from_path(self, path): | ||
| content_response = self.get_content_from_path(path) |
| return string_data | ||
|
|
||
| def update_content_from_path(self, path, content): | ||
| url = URLS.get("contents").format(self.GITHUB_REPOSITORY, path) |
|
|
||
| @app.task | ||
| def github_challenge_phase_sync(challenge_phase): | ||
| from .serializers import ChallengePhaseSerializer |
There was a problem hiding this comment.
Since it is a circular import.
| from .serializers import ChallengePhaseSerializer | ||
|
|
||
| for obj in serializers.deserialize("json", challenge_phase): | ||
| challenge_phase_obj = obj.object |
There was a problem hiding this comment.
create a util method for deserializing and use that
| "is_restricted_to_select_one_submission", | ||
| "is_partial_submission_evaluation_enabled", | ||
| "allowed_submission_file_types", | ||
| ] |
| github.update_data_from_path("challenge_config.yaml", content_str) | ||
|
|
||
| # File fields Update | ||
| file_fields = ["description"] |
| def github_sync_challenge(sender, instance, created, **kwargs): | ||
| if instance.github_repository and instance.github_token: | ||
| serialized_obj = serializers.serialize("json", [instance]) | ||
| github_challenge_sync.delay(serialized_obj) |
There was a problem hiding this comment.
@savish28 the method names are confusing github_challenge_sync and github_sync_challenge (post save hook) it is not clear what these methods are for. Please rename the methods.
|
@RishabhJain2018 Yes it is!! |
| @@ -0,0 +1,37 @@ | |||
| # Fields from Challenge, ChallengePhase model to be considered for github_sync | |||
|
|
|||
| challenge_non_file_fields = [ | |||
There was a problem hiding this comment.
@savish28 is there a way we can use the serializer or model to generate this list of fields? Currently, if a new field gets added we'll have to add it here manually. It might happen that some forgets adding it here which would mean there is no sync happening for that field. If we can use models/serializer for this list it would be great
There was a problem hiding this comment.
@Ram81, we only wish to have only selected fields(that are editable from frontend) in the sync and not all fields, getting it from serializer would mean using all fields and that is undesirable because there are a lot of fields that are not in the challenge_config and might also be critical to share those.
| URLS = {"contents": "/repos/{}/contents/{}", "repos": "/repos/{}"} | ||
|
|
||
|
|
||
| class GithubInterface: |
There was a problem hiding this comment.
@savish28 can we move this class to a separate file called github_interface.py
| if not github.is_repository(): | ||
| return | ||
| try: | ||
| # Challenge Non-file field Update |
There was a problem hiding this comment.
Change to Challenge non-file field update
| content_str = yaml.dump(challenge_config_yaml, sort_keys=False) | ||
| github.update_data_from_path("challenge_config.yaml", content_str) | ||
|
|
||
| # Challenge File fields Update |
There was a problem hiding this comment.
Change to Challenge file fields update
| continue | ||
| github.update_data_from_path(field_path, getattr(challenge, field)) | ||
| except Exception as e: | ||
| logger.info("Github Sync unsuccessful due to {}".format(e)) |
There was a problem hiding this comment.
Why is this a info log? This should be a error log
| field_path, getattr(challenge_phase, field) | ||
| ) | ||
| break | ||
|
|
| github.update_data_from_path( | ||
| field_path, getattr(challenge_phase, field) | ||
| ) | ||
| break |
There was a problem hiding this comment.
Because at a time only one challenge_phase is updated. Because it is initiated by post-hook of ChallengePhase
| break | ||
|
|
||
| except Exception as e: | ||
| logger.info( |
There was a problem hiding this comment.
same here, Why is this not a error log?
|
|
||
|
|
||
| @receiver(signals.post_save, sender="challenges.Challenge") | ||
| def challenge_sync(sender, instance, created, **kwargs): |
|
|
||
|
|
||
| @receiver(signals.post_save, sender="challenges.ChallengePhase") | ||
| def challenge_phase_sync(sender, instance, created, **kwargs): |
There was a problem hiding this comment.
change to challenge_phase_details_sync
|
@Ram81 Ping! :) |
|
Thanks for the ping @savish28. I will review this PR today |
Context: Github Bi-directional Sync
Related Pull Request: Cloud-CV/EvalAI-Starters#52
Models Considered:
Deliverables:
Testing without celery:
https://user-images.githubusercontent.com/32800267/129727539-80d18fd0-7cdc-489d-a3c6-0b346ce605c8.mp4
@KhalidRmb
cc: @Ram81