Skip to content

Archive El Segundo and Sierra Madre feeds (service discontinued) #1359

Archive El Segundo and Sierra Madre feeds (service discontinued)

Archive El Segundo and Sierra Madre feeds (service discontinued) #1359

Workflow file for this run

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@de0fac2e4500dabe0009e67214ff5f5447ce83dd # 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
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7
env:
DIFF: ${{ steps.git-diff.outputs.git_diff }}
with:
script: |
const diff = process.env.DIFF || '';
const botComments = await github.paginate(github.rest.issues.listComments, {
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo
});
const prior = botComments.find(c =>
c.user.type === 'Bot' &&
c.body.includes('DMFR Format Check Results')
);
let body;
if (diff) {
body = `## 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! 🚀`;
} else if (prior) {
// No formatting changes needed in the latest push, but a prior bot
// comment flagged issues — replace it with a resolved message.
body = `## DMFR Format Check Results
✅ DMFR formatting is now correct.`;
} else {
// No diff and no prior comment — nothing to do.
return;
}
if (prior) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: prior.id,
body
});
} else {
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body
});
}