Skip to content

Commit 0889d44

Browse files
committed
Sync .github directory from main branch
- Applied .github directory from main to morriscode-patch-1 - Ensures workflows and GitHub configurations are up to date - Automated sync via script
1 parent b8ce90e commit 0889d44

File tree

6 files changed

+665
-177
lines changed

6 files changed

+665
-177
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.yml @sublime-security/Detection

.github/pull_request_template.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Description
2+
3+
<!--
4+
Explain your change and why. For example, "negating legitimate replies," or "adding additional credential theft keywords."
5+
6+
If it's a new rule or insight, explain what the rule is designed to catch/what the insight should fire on.
7+
-->
8+
9+
# Associated samples
10+
<!--
11+
Link to samples that are affected by your change.
12+
13+
For example, samples you are negating, samples you are including, or samples your new insight should fire on.
14+
-->
15+
16+
- Sample 1
17+
- Sample 2
18+
19+
## Associated hunts
20+
<!--
21+
22+
If you ran any hunts with your rule, please link them here.
23+
-->
24+
25+
- Hunt 1
26+
27+
# Screenshot (insights)
28+
<!--
29+
**For new insights only:** Insert a screenshot of the insight firing. Remove this section if not applicable.
30+
-->

.github/workflows/clear-old-test-rules.yml

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,34 @@ on:
99

1010
jobs:
1111
remove-stale:
12-
runs-on: ubuntu-20.04
12+
runs-on: ubuntu-latest
1313
permissions:
1414
contents: write
1515
pull-requests: read
1616

1717
steps:
1818
- name: Checkout repository
19-
uses: actions/checkout@v3
19+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
2020
with:
2121
ref: "test-rules"
2222
path: destination
2323

2424
- name: Get Open PRs
2525
id: open_prs
26+
# this needs to be upgraded to v7 but need to get this working now
27+
# actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
2628
uses: actions/github-script@v4
2729
with:
2830
script: |
29-
github.pulls.list({
30-
owner: context.repo.owner,
31-
repo: context.repo.repo,
32-
state: 'open'
33-
}).then((result) => {
34-
const openPRs = result.data.map(pr => pr.number);
31+
github.paginate(
32+
github.pulls.list,
33+
{
34+
owner: context.repo.owner,
35+
repo: context.repo.repo,
36+
state: 'open',
37+
},
38+
(response) => response.data.map((pr) => pr.number)
39+
).then((openPRs) => {
3540
console.log(`::set-output name=open_prs::${openPRs.join(',')}`);
3641
});
3742
@@ -43,15 +48,17 @@ jobs:
4348
echo "This is a forked repository. Skipping the job."
4449
exit 0
4550
fi
51+
52+
echo "Open PRs: [$OPEN_PRS]"
4653
4754
echo "Scheduled cleanup" > message.txt
4855
echo "" >> message.txt
4956
5057
cd destination
51-
files=$(ls **/*.yml) || true
58+
files=$(ls -- **/*.yml) || true
5259
5360
for file in $files; do
54-
file_pr_num=$(yq '.testing_pr' $file)
61+
file_pr_num=$(yq '.testing_pr' "$file")
5562
in_open_pr=false
5663
5764
IFS=',' read -ra PR_ARRAY <<< "$OPEN_PRS"
@@ -61,8 +68,9 @@ jobs:
6168
fi
6269
done
6370
71+
echo "$file is in open PR: $in_open_pr. File PR num: $file_pr_num"
6472
if [[ "$in_open_pr" = "false" ]]; then
65-
rm $file
73+
rm "$file"
6674
echo "Removed $file_pr_num" >> ../message.txt
6775
fi
6876
done

.github/workflows/pr-auto-tag.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Auto-tag External PRs
2+
3+
on:
4+
pull_request_target:
5+
types: [opened, ready_for_review]
6+
7+
jobs:
8+
auto-tag:
9+
runs-on: ubuntu-latest
10+
permissions:
11+
pull-requests: write
12+
steps:
13+
- name: Check if PR author is external
14+
uses: actions/github-script@v7
15+
with:
16+
script: |
17+
const pr = context.payload.pull_request;
18+
const username = pr.user.login;
19+
const authorAssociation = pr.author_association;
20+
21+
console.log(`PR author: ${username}`);
22+
console.log(`Author association: ${authorAssociation}`);
23+
24+
// MEMBER, OWNER, and COLLABORATOR are considered internal
25+
const internalAssociations = ['MEMBER', 'OWNER', 'COLLABORATOR'];
26+
const isInternal = internalAssociations.includes(authorAssociation);
27+
28+
if (!isInternal) {
29+
console.log('User is external, adding review-needed label');
30+
await github.rest.issues.addLabels({
31+
owner: context.repo.owner,
32+
repo: context.repo.repo,
33+
issue_number: pr.number,
34+
labels: ['review-needed']
35+
});
36+
console.log('Added review-needed label to external PR');
37+
} else {
38+
console.log(`User is internal (${authorAssociation}), no label added`);
39+
}

0 commit comments

Comments
 (0)