-
Notifications
You must be signed in to change notification settings - Fork 220
118 lines (102 loc) · 3.81 KB
/
format.yaml
File metadata and controls
118 lines (102 loc) · 3.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
name: Comment on PRs that need DMFR formatting changes
on:
pull_request_target:
paths:
- 'feeds/**'
permissions:
issues: write
pull-requests: write
contents: read
jobs:
format:
name: Check DMFR Formatting
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
# Only needed for fork PRs - security check
- name: Security check for fork PRs
if: ${{ github.event.pull_request.head.repo.full_name != github.repository }}
run: |
# Check if PR modifies .github or scripts directories
if git diff --name-only ${{ github.event.pull_request.head.sha }} ${{ github.event.pull_request.base.sha }} | grep -q -E "^\.github/|^scripts/"; then
echo "Error: PR contains changes to .github or scripts directories, which is not allowed for security reasons"
exit 1
fi
- name: Install transitland-lib
id: install
run: scripts/install-transitland-lib.sh
continue-on-error: false
- name: Format DMFR files
id: format
run: |
set -euo pipefail # Fail on any error
find ./feeds -type f -name "*.dmfr.json" -exec transitland dmfr format --save {} \;
- name: Check for formatting changes
id: git-diff
run: |
set -euo pipefail # Fail on any error
git_status_output="$(git status --porcelain)" || {
echo "Error running git status: $?"
exit 1
}
if [ -z "$git_status_output" ]; then
echo "No formatting changes needed"
else
echo "Formatting changes required"
echo "Git status:"
echo "$git_status_output"
echo "Git diff:"
git diff
echo "git_diff<<EOF" >> "$GITHUB_OUTPUT"
git diff >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"
fi
- name: Comment on PR
if: ${{ steps.git-diff.outputs.git_diff != '' }}
uses: actions/github-script@v7
env:
DIFF: ${{ steps.git-diff.outputs.git_diff }}
with:
script: |
const diff = process.env.DIFF;
// Get existing bot comments to avoid duplicates
const botComments = await github.paginate(github.rest.issues.listComments, {
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo
});
const botComment = botComments.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('DMFR Format Check Results')
);
const commentBody = `## DMFR Format Check Results
This PR includes files that need formatting adjustments to follow the "opinionated" DMFR format.
### Suggested Changes:
\`\`\`diff
${diff}
\`\`\`
You can apply these changes by:
1. Using a code editor
2. Running [transitland-lib](https://github.com/interline-io/transitland-lib/blob/main/dmfr-command.md) locally
3. Waiting for a maintainer to help
Thank you for contributing to Transitland Atlas! 🚀`;
if (botComment) {
// Update existing comment
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: commentBody
});
} else {
// Create new comment
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentBody
});
}