Skip to content

Commit 67945c0

Browse files
authored
Merge pull request #548 from dependabot/nishnha/specify-if-conditional
Update readme to include an if conditional
2 parents ffa2dc8 + 46e21c9 commit 67945c0

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

README.md

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ Extract information about the dependencies being updated by a Dependabot-generat
1414

1515
## Usage instructions
1616

17-
Create a workflow file that contains a step that uses: `dependabot/fetch-metadata@v1`, e.g.
17+
Create a workflow file that contains a step that uses: `dependabot/fetch-metadata@v2`, e.g.
1818

1919
```yaml
2020
-- .github/workflows/dependabot-prs.yml
2121
name: Dependabot Pull Request
22-
on: pull_request_target
22+
on: pull_request
23+
if: github.event.pull_request.user.login == 'dependabot[bot]' && github.repository == 'owner/my_repo'
2324
jobs:
2425
build:
2526
permissions:
@@ -28,7 +29,7 @@ jobs:
2829
steps:
2930
- name: Fetch Dependabot metadata
3031
id: dependabot-metadata
31-
uses: dependabot/fetch-metadata@v1
32+
uses: dependabot/fetch-metadata@v2
3233
with:
3334
alert-lookup: true
3435
compat-lookup: true
@@ -92,6 +93,8 @@ Subsequent actions will have access to the following outputs:
9293
**Note:** By default, these outputs will only be populated if the target Pull Request was opened by Dependabot and contains
9394
**only** Dependabot-created commits. To override, see `skip-commit-verification` / `skip-verification`.
9495

96+
For workflows initiated by Dependabot (`github.actor == 'dependabot[bot]'`) using the `pull_request_target` event, if the base ref of the pull request was created by Dependabot (`github.event.pull_request.user.login == 'dependabot[bot]'`), the `GITHUB_TOKEN` will be read-only and secrets are not available.
97+
9598
This metadata can be used along with Action's [expression syntax](https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#functions) and the [GitHub CLI](https://github.com/cli/cli) to create
9699
useful automation for your Dependabot PRs.
97100

@@ -102,18 +105,18 @@ have a permissive auto-approval on all Dependabot PRs like so:
102105

103106
```yaml
104107
name: Dependabot auto-approve
105-
on: pull_request_target
108+
on: pull_request
106109
permissions:
107110
pull-requests: write
108111
jobs:
109112
dependabot:
110113
runs-on: ubuntu-latest
111114
# Checking the author will prevent your Action run failing on non-Dependabot PRs
112-
if: ${{ github.event.pull_request.user.login == 'dependabot[bot]' }}
115+
if: github.event.pull_request.user.login == 'dependabot[bot]' && github.repository == 'owner/my_repo'
113116
steps:
114117
- name: Dependabot metadata
115118
id: dependabot-metadata
116-
uses: dependabot/fetch-metadata@v1
119+
uses: dependabot/fetch-metadata@v2
117120
- uses: actions/checkout@v4
118121
- name: Approve a PR if not already approved
119122
run: |
@@ -136,18 +139,18 @@ For example, if you want to automatically merge all patch updates to Rails:
136139
137140
```yaml
138141
name: Dependabot auto-merge
139-
on: pull_request_target
142+
on: pull_request
140143
permissions:
141144
pull-requests: write
142145
contents: write
143146
jobs:
144147
dependabot:
145148
runs-on: ubuntu-latest
146-
if: ${{ github.event.pull_request.user.login == 'dependabot[bot]' }}
149+
if: github.event.pull_request.user.login == 'dependabot[bot]' && github.repository == 'owner/my_repo'
147150
steps:
148151
- name: Dependabot metadata
149152
id: dependabot-metadata
150-
uses: dependabot/fetch-metadata@v1
153+
uses: dependabot/fetch-metadata@v2
151154
- name: Enable auto-merge for Dependabot PRs
152155
if: ${{contains(steps.dependabot-metadata.outputs.dependency-names, 'rails') && steps.dependabot-metadata.outputs.update-type == 'version-update:semver-patch'}}
153156
run: gh pr merge --auto --merge "$PR_URL"
@@ -164,19 +167,19 @@ For example, if you want to flag all production dependency updates with a label:
164167
165168
```yaml
166169
name: Dependabot auto-label
167-
on: pull_request_target
170+
on: pull_request
168171
permissions:
169172
pull-requests: write
170173
issues: write
171174
repository-projects: write
172175
jobs:
173176
dependabot:
174177
runs-on: ubuntu-latest
175-
if: ${{ github.event.pull_request.user.login == 'dependabot[bot]' }}
178+
if: github.event.pull_request.user.login == 'dependabot[bot]' && github.repository == 'owner/my_repo'
176179
steps:
177180
- name: Dependabot metadata
178181
id: dependabot-metadata
179-
uses: dependabot/fetch-metadata@v1
182+
uses: dependabot/fetch-metadata@v2
180183
- name: Add a label for all production dependencies
181184
if: ${{ steps.dependabot-metadata.outputs.dependency-type == 'direct:production' }}
182185
run: gh pr edit "$PR_URL" --add-label "production"

0 commit comments

Comments
 (0)