Repository: nautobot/nautobot

Issue:
Git `provided_contents` not honored for Jobs when refreshing repo
<!--
    NOTE: IF YOUR ISSUE DOES NOT FOLLOW THIS TEMPLATE, IT WILL BE CLOSED.

    This form is only for reporting reproducible bugs. If you need assistance
    with Nautobot installation, or if you have a general question, please start a
    discussion instead: https://github.com/nautobot/nautobot/discussions

    Please describe the environment in which you are running Nautobot. Be sure
    that you are running an unmodified instance of the latest stable release
    before submitting a bug report, and that any plugins have been disabled.
-->
### Environment
* Nautobot version (Docker tag too if applicable): 1.4.5
* Python version: 3.10
* Database platform, version: pgsql
* Middleware(s):

<!--
    Describe in detail the exact steps that someone else can take to reproduce
    this bug using the current stable release of Nautobot. Begin with the
    creation of any necessary database objects and call out every operation
    being performed explicitly. If reporting a bug in the REST API, be sure to
    reconstruct the raw HTTP request(s) being made: Don't rely on a client
    library such as pynautobot.
-->
### Steps to Reproduce
1. Create a repo which hosts valid jobs, but do not select `jobs` in "Provides"
2. Save & sync

<!-- What did you expect to happen? -->
### Expected Behavior
Jobs are not installed (or removed if previously selected in provides)

<!-- What happened instead? -->
### Observed Behavior
Jobs are installed

### Additional informations

The missing condition, like in `_get_job_source_paths`, seems to be in [`refresh_git_jobs`](https://github.dev/nautobot/nautobot/blob/v1.4.5/nautobot/extras/datasources/git.py#L913)



Discussion:
Thanks for the report!

I must be missing some nuance of the code, because this *should* be working correctly with the [`if not delete:` check](https://github.com/nautobot/nautobot/blob/develop/nautobot/extras/datasources/git.py#L916) preventing the jobs from being loaded (refreshing a repo without the appropriate "provides" flag set will call the refresh function with `delete=True`). 
The only call with `delete=True` I could find is https://github.com/nautobot/nautobot/blob/v1.4.5/nautobot/extras/signals.py#L208, but this is when the repo is deleted, not when a content type is disabled. On refresh, `delete=False` : https://github.com/nautobot/nautobot/blob/v1.4.5/nautobot/extras/datasources/git.py#L161
You're right, my mistake. I was thinking of the [`if "extras.configcontextschema" in repository_record.provided_contents and not delete:` pattern](https://github.com/nautobot/nautobot/blob/v1.4.5/nautobot/extras/datasources/git.py#L762), and as you noted the Job case is missing a `if "extras.job" in repository_record.provided_contents` check.

Resolving patch:
diff --git a/nautobot/extras/datasources/git.py b/nautobot/extras/datasources/git.py
--- a/nautobot/extras/datasources/git.py
+++ b/nautobot/extras/datasources/git.py
@@ -913,7 +913,7 @@ def delete_git_config_context_schemas(repository_record, job_result, preserve=()
 def refresh_git_jobs(repository_record, job_result, delete=False):
     """Callback function for GitRepository updates - refresh all Job records managed by this repository."""
     installed_jobs = []
-    if not delete:
+    if "extras.job" in repository_record.provided_contents and not delete:
         jobs_path = os.path.join(repository_record.filesystem_path, "jobs")
         if os.path.isdir(jobs_path):
             for job_info in jobs_in_directory(jobs_path, report_errors=True):


Test patch: