Content-Length: 344214 | pFad | http://github.com/nautobot/nautobot/pull/6752/commits/0a26195ec9ef23350214fca263a0ead3b75e06a1

BF GraphQL as a Git Data source provider. by djhoward12 · Pull Request #6752 · nautobot/nautobot · GitHub
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

GraphQL as a Git Data source provider. #6752

Merged
merged 23 commits into from
Jan 23, 2025
Merged
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
8428c21
initial commit for graphql as a git data source
Jan 9, 2025
c2442f5
Merge branch 'develop' of https://github.com/djhoward12/nautobot into…
Jan 9, 2025
0a26195
Adding conditional for isdir and stripped extension from filename whe…
Jan 9, 2025
89f42b9
Merge branch 'nautobot:develop' into develop
djhoward12 Jan 9, 2025
934cbce
Update nautobot/docs/user-guide/feature-guides/git-data-source.md
djhoward12 Jan 9, 2025
22f63dd
Update nautobot/docs/user-guide/feature-guides/git-data-source.md
djhoward12 Jan 9, 2025
00ca2e2
Update nautobot/docs/user-guide/feature-guides/git-data-source.md
djhoward12 Jan 9, 2025
e24c920
Update nautobot/extras/datasources/git.py
djhoward12 Jan 9, 2025
bd37894
Adjusting tests for missing .gql extension and updates per PR comments.
Jan 10, 2025
317b021
Merge branch 'nautobot:develop' into develop
djhoward12 Jan 10, 2025
dfedd27
Merge branch 'develop' into develop
HanlinMiao Jan 15, 2025
e1574e8
Addressing PR comments, clear error msg, spelling error, add flag, up…
Jan 16, 2025
04c4e70
Merge branch 'develop' into develop
djhoward12 Jan 16, 2025
71f79df
Addressing PR comments. Don't delete query if exists and update has s…
Jan 16, 2025
806dc77
Merge branch 'nautobot:develop' into develop
djhoward12 Jan 16, 2025
290a92c
Update nautobot/extras/datasources/git.py
djhoward12 Jan 16, 2025
0242a2f
moving query=query content inside if. removing extra appends.
Jan 16, 2025
c8f4ae0
Merge branch 'develop' into develop
djhoward12 Jan 17, 2025
a0e241b
Merge branch 'develop' into develop
glennmatthews Jan 21, 2025
b917d0e
updating documentation to be in line with updates in #6801.
Jan 22, 2025
0693ee8
Merge branch 'nautobot:develop' into develop
djhoward12 Jan 22, 2025
30b476b
Merge branch 'develop' into develop
glennmatthews Jan 22, 2025
9c2df03
Update changes/4702.added
glennmatthews Jan 22, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Adding conditional for isdir and stripped extension from filename whe…
…n creating query.
  • Loading branch information
“DJ committed Jan 9, 2025
commit 0a26195ec9ef23350214fca263a0ead3b75e06a1
88 changes: 47 additions & 41 deletions nautobot/extras/datasources/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -958,55 +958,61 @@ def update_git_graphql_queries(repository_record, job_result):
git_repository_content_type = ContentType.objects.get_for_model(GitRepository)
graphql_queries = []

for file in os.listdir(graphql_query_path):
file_path = os.path.join(graphql_query_path, file)
if not os.path.isfile(file_path):
continue
if os.path.isdir(graphql_query_path):
for file in os.listdir(graphql_query_path):
file_path = os.path.join(graphql_query_path, file)
if not os.path.isfile(file_path):
continue

try:
with open(file_path, "r") as fd:
query_content = fd.read().strip()
# Remove `.gql` extension from the name if it exists
query_name = file.rsplit(".gql", 1)[0] if file.endswith(".gql") else file

graphql_query, created = GraphQLQuery.objects.get_or_create(
name=file,
query= query_content,
owner_content_type=git_repository_content_type,
owner_object_id=repository_record.pk,
)
modified = False
try:
with open(file_path, "r") as fd:
query_content = fd.read().strip()

graphql_query, created = GraphQLQuery.objects.get_or_create(
name=query_name,
query=query_content,
owner_content_type=git_repository_content_type,
owner_object_id=repository_record.pk,
djhoward12 marked this conversation as resolved.
Show resolved Hide resolved
)
modified = False

# Check and update the query content
if graphql_query.query != query_content:
graphql_query.query = query_content
modified = True
# Check and update the query content
if graphql_query.query != query_content:
graphql_query.query = query_content
djhoward12 marked this conversation as resolved.
Show resolved Hide resolved
modified = True

# Associate the query with the repository (if needed)
owner_content_type = ContentType.objects.get_for_model(repository_record)
if graphql_query.owner_content_type != owner_content_type:
graphql_query.owner_content_type = owner_content_type
graphql_query.owner_object_id = repository_record.pk
modified = True
# Associate the query with the repository (if needed)
owner_content_type = ContentType.objects.get_for_model(repository_record)
djhoward12 marked this conversation as resolved.
Show resolved Hide resolved
if graphql_query.owner_content_type != owner_content_type:
graphql_query.owner_content_type = owner_content_type
graphql_query.owner_object_id = repository_record.pk
modified = True
djhoward12 marked this conversation as resolved.
Show resolved Hide resolved

if modified:
graphql_query.save()
if modified:
graphql_query.save()

graphql_queries.append(file)
graphql_queries.append(query_name)

# Log success
if created:
msg = f"Successfully created GraphQL query: {file}"
elif modified:
msg = f"Successfully refreshed GraphQL query: {file}"
else:
msg = f"No changes to GraphQL query: {file}"
logger.info(msg)
job_result.log(msg, obj=graphql_query, level_choice=LogLevelChoices.LOG_INFO, grouping="graphql queries")
# Log success
if created:
msg = f"Successfully created GraphQL query: {query_name}"
elif modified:
msg = f"Successfully refreshed GraphQL query: {query_name}"
else:
msg = f"No changes to GraphQL query: {query_name}"
logger.info(msg)
job_result.log(
msg, obj=graphql_query, level_choice=LogLevelChoices.LOG_INFO, grouping="graphql queries"
)

except Exception as exc:
# Log the error but continue processing other files
error_msg = f"Error processing GraphQL query file '{file}': {exc}"
logger.error(error_msg)
job_result.log(error_msg, level_choice=LogLevelChoices.LOG_ERROR, grouping="graphql queries")
except Exception as exc:
# Log the error but continue processing other files
error_msg = f"Error processing GraphQL query file '{file}': {exc}"
djhoward12 marked this conversation as resolved.
Show resolved Hide resolved
logger.error(error_msg)
job_result.log(error_msg, level_choice=LogLevelChoices.LOG_ERROR, grouping="graphql queries")

# Delete any queries not in the preserved list
delete_git_graphql_queries(repository_record, job_result, preserve=graphql_queries)
Expand Down








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/nautobot/nautobot/pull/6752/commits/0a26195ec9ef23350214fca263a0ead3b75e06a1

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy