Repository: dbt-labs/dbt-core
Pull request: update triggers to use issues for opening docs issues
resolves https://github.com/dbt-labs/actions/issues/162


### Problem

PRs have to get labeled when we're already labeling the issues.  Some PRs never make it to getting docs PRs created.

### Solution

Trigger docs issues to be created when an issue has the `user_docs` label and is closed as completed.

### Checklist

- [ ] I have read [the contributing guide](https://github.com/dbt-labs/dbt-core/blob/main/CONTRIBUTING.md) and understand what's expected of me  
- [ ] I have run this code in development and it appears to resolve the stated issue  
- [ ] This PR includes tests, or tests are not required/relevant for this PR
- [ ] This PR has no interface changes (e.g. macros, cli, logs, json artifacts, config files, adapter interface, etc) or this PR has already received feedback and approval from Product or DX
- [ ] This PR includes [type annotations](https://docs.python.org/3/library/typing.html) for new and modified functions


Problem statement:
Create issues in docs.getdbt.com off os issues instead of PRs
### Housekeeping

- [X] I am a maintainer of actions

### Short description

We add the `user docs` label to issues to identify it needs to have a change to docs.getdbt.com.  We then have to add them to PRs to get the issues to actually be created.  Instead lets just trigger the docs.getdbt.com to create a new issue when the issue with that label is closed or that label is added to a close issue.

### Acceptance criteria

- When an issue is closed and has the label `user_docs`, open an issue in docs.getdbt.com
- When a closed issued is label with `user_docs`, open an issue in docs.getdbt.com

### Impact to Other Teams

docs team, PM/DX

### Context

Open question: Can we see when an issue is closed as not planned instead of as completed?  When that's the case we don't really want to open a docs issue.

Note that the triggers in the repos need to be adjusted to work off issues.
The workflow in this repo needs to be modified to looks at issue numbers and issue comments instead of PR numbers.

Hints from issue discussion:

Commit message: update triggers to use issues

Patch to review:
diff --git a/.github/workflows/docs-issue.yml b/.github/workflows/docs-issue.yml
index 00a098df827..f5b04e6d1fa 100644
--- a/.github/workflows/docs-issue.yml
+++ b/.github/workflows/docs-issue.yml
@@ -5,15 +5,14 @@
 # To reduce barriers for keeping docs up to date
 
 # **when?**
-# When a PR is labeled `user docs` and is merged.  Runs on pull_request_target to run off the workflow already merged,
-# not the workflow that existed on the PR branch.  This allows old PRs to get comments.
+# When an issue is labeled `user docs` and is closed as completed.  Can be labeled before or after the issue is closed.
 
 
 name: Open issues in docs.getdbt.com repo when a PR is labeled
 run-name: "Open an issue in docs.getdbt.com for PR #${{ github.event.pull_request.number }}"
 
 on:
-  pull_request_target:
+  issues:
     types: [labeled, closed]
 
 defaults:
@@ -21,20 +20,19 @@ defaults:
     shell: bash
 
 permissions:
-    issues: write # opens new issues
-    pull-requests: write # comments on PRs
-
+    issues: write # comments on issues
 
 jobs:
   open_issues:
-    # we only want to run this when the PR has been merged or the label in the labeled event is `user docs`.  Otherwise it runs the
+    # we only want to run this when the is closed as completed and the label `user docs` has been assigned.
+    # If this logic does nto exist in this workflow, it runs the
     # risk of duplicaton of issues being created due to merge and label both triggering this workflow to run and neither having
     # generating the comment before the other runs.  This lives here instead of the shared workflow because this is where we
     # decide if it should run or not.
     if: |
-      (github.event.pull_request.merged == true) &&
-      ((github.event.action == 'closed' && contains( github.event.pull_request.labels.*.name, 'user docs')) ||
-      (github.event.action == 'labeled' && github.event.label.name == 'user docs'))
+      (github.event.issue.state == 'closed' &&
+       github.event.issue.state_reason == 'completed' &&
+       contains( github.event.pull_request.labels.*.name, 'user docs'))
     uses: dbt-labs/actions/.github/workflows/open-issue-in-repo.yml@main
     with:
         issue_repository: "dbt-labs/docs.getdbt.com"


Code review comments:
diff_hunk: @@ -5,36 +5,34 @@
 # To reduce barriers for keeping docs up to date
 
 # **when?**
-# When a PR is labeled `user docs` and is merged.  Runs on pull_request_target to run off the workflow already merged,
-# not the workflow that existed on the PR branch.  This allows old PRs to get comments.
+# When an issue is labeled `user docs` and is closed as completed.  Can be labeled before or after the issue is closed.
 
 
 name: Open issues in docs.getdbt.com repo when a PR is labeled
 run-name: "Open an issue in docs.getdbt.com for PR #${{ github.event.pull_request.number }}"
 
 on:
-  pull_request_target:
+  issues:
     types: [labeled, closed]
 
 defaults:
   run:
     shell: bash
 
 permissions:
-    issues: write # opens new issues
-    pull-requests: write # comments on PRs
-
+    issues: write # comments on issues
 
 jobs:
   open_issues:
-    # we only want to run this when the PR has been merged or the label in the labeled event is `user docs`.  Otherwise it runs the
+    # we only want to run this when the is closed as completed and the label `user docs` has been assigned.
path: .github/workflows/docs-issue.yml
text: @user1:
Nit: missing word `issue`
```suggestion
    # we only want to run this when the issue is closed as completed and the label `user docs` has been assigned.
```

diff_hunk: @@ -5,36 +5,34 @@
 # To reduce barriers for keeping docs up to date
 
 # **when?**
-# When a PR is labeled `user docs` and is merged.  Runs on pull_request_target to run off the workflow already merged,
-# not the workflow that existed on the PR branch.  This allows old PRs to get comments.
+# When an issue is labeled `user docs` and is closed as completed.  Can be labeled before or after the issue is closed.
 
 
 name: Open issues in docs.getdbt.com repo when a PR is labeled
 run-name: "Open an issue in docs.getdbt.com for PR #${{ github.event.pull_request.number }}"
 
 on:
-  pull_request_target:
+  issues:
     types: [labeled, closed]
 
 defaults:
   run:
     shell: bash
 
 permissions:
-    issues: write # opens new issues
-    pull-requests: write # comments on PRs
-
+    issues: write # comments on issues
 
 jobs:
   open_issues:
-    # we only want to run this when the PR has been merged or the label in the labeled event is `user docs`.  Otherwise it runs the
+    # we only want to run this when the is closed as completed and the label `user docs` has been assigned.
+    # If this logic does nto exist in this workflow, it runs the
path: .github/workflows/docs-issue.yml
text: @user1:
Nit: typo

```suggestion
    # If this logic does not exist in this workflow, it runs the
```