Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: initial Github application #1

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

feat: initial Github application #1

wants to merge 8 commits into from

Conversation

bogdanoniga
Copy link
Contributor

No description provided.

@bogdanoniga bogdanoniga requested a review from a team as a code owner May 15, 2023 14:21

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would be nice to keep these files for consistency with all other projects - unless they're not needed? 🤔

if not integration.enabled:
continue

GITHUB_TOKEN = _get_token(integration.app_id, integration.secrets, integration.app_installation_id)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a constant anyway :P If it was like a single-time fetched result, it would be ok - but this is not as much.

Suggested change
GITHUB_TOKEN = _get_token(integration.app_id, integration.secrets, integration.app_installation_id)
github_token = _get_token(integration.app_id, integration.secrets, integration.app_installation_id)

self._parse_users(integration)
self._parse_teams(integration)

def _parse_users(self, integration):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any advantage of using GitHub's GraphQL instead of the regular API? I know, the answer is probably tidier but this type of queries are a bit cumbersome to read 🙃

variables = {'organisation': integration.organisation}

response = requests.post(
'https://api.github.com/graphql', json={'query': query, 'variables': variables}, headers=self.headers

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

api.github.com might be a good candidate for a constant variable somewhere in this script :)

'https://api.github.com/graphql', json={'query': query, 'variables': variables}, headers=self.headers
)

if response.status_code == 200:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of this if/else, try response.raise_for_status() and then to the body parsing. It's much cleaner and built-in in the requests lib.


class GithubTeam(models.Model):
id = models.CharField(max_length=128, null=False, primary_key=True, editable=False)
name = models.CharField(max_length=128, null=False, editable=False)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

null=False is the default, no need to write it there.

number = models.IntegerField(editable=False)
repository = models.ForeignKey('inventory.GitRepository', on_delete=models.CASCADE, editable=False)
url = models.URLField(null=True, blank=True, editable=False)
secret_type = models.CharField(max_length=255, null=True, blank=True, editable=False)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this be a good candidate for a enumerator? Type suggests that.

@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be great if you could write some, not gonna lie 🙃

return f'{self.pk} [{self.cached_content_source.app_label}] - {self.name}'


class Application(models.Model):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A suggestion could be to use Surface as a lib instead of copy/pasting these fields.

Comment on lines +2 to +4
pytest==6.2.5
pytest-cov==2.12.1
pytest-django==4.4.0

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These versions should be bumped to the latest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants