Skip to content

Fetch Commits on gbfs.md and create an issue with details #17

Fetch Commits on gbfs.md and create an issue with details

Fetch Commits on gbfs.md and create an issue with details #17

name: Fetch Commits on gbfs.md and create an issue with details
env:
ASSIGNED: "josee-sabourin" # Comma-separated list of assignees
GIT_USERNAME: "github-actions[bot]"
GIT_EMAIL: "41898282+github-actions[bot]@users.noreply.github.com"
REMOTE_REPO_OWNER: "MobilityData"
REMOTE_REPO_NAME: "gbfs"
REMOTE_REPO_FILE_TO_CHECK: "gbfs.md"
ISSUE_LABELS_TO_APPLY: "gbfs-md" # comma-delimited list
on:
schedule:
- cron: '0 0 * * *' # Runs daily at midnight UTC
jobs:
fetch-and-create-pr:
runs-on: ubuntu-latest
steps:
- name: Checkout master of gbfs.mobilitydata.org repo
uses: actions/[email protected]
with:
ref: master
fetch-depth: 0
token: ${{ secrets.GENERIC_ACTION_REPO_SCOPE }}
- name: Use Node.js 16.x
uses: actions/[email protected]
with:
node-version: '16.x'
- name: Install Node.js dependencies
run: npm install @actions/github
- name: Set up Git
id: git-setup
run: |
git config user.name ${{ env.GIT_USERNAME }}
git config user.email ${{ env.GIT_EMAIL }}
- name: Calculate Dates
id: dates
run: |
echo "yesterday=$(date -d '-1 day' '+%Y-%m-%d')" >> $GITHUB_OUTPUT
echo "today=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT
- name: Fetch commits and process JSON
id: process_json
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GENERIC_ACTION_REPO_SCOPE }}
script: |
const response = await github.request('GET /repos/${{ env.REMOTE_REPO_OWNER }}/${{ env.REMOTE_REPO_NAME }}/commits', {
owner: '${{ env.REMOTE_REPO_OWNER }}',
repo: '${{ env.REMOTE_REPO_NAME }}',
path: '${{ env.REMOTE_REPO_FILE_TO_CHECK }}',
since: '${{ steps.dates.outputs.yesterday}}T00:00:00Z',
});
const commits = response.data;
core.setOutput('commits_data', commits);
core.setOutput('commits_length', commits.length);
if (commits.length > 0) {
const extractedData = commits.map(item => ({
author: item.commit.author.name,
username: item.author.login,
date: item.commit.author.date,
message: item.commit.message.replace(/\n\s*\n/g, '\n'),
html_url: item.html_url
}));
const formattedExtractedData = extractedData.map((item, index) => {
const dateObjectUTC = new Date(item.date);
const dateObjectETC = new Date(dateObjectUTC.toLocaleString('en-US', { timeZone: 'America/Toronto' }));
const formattedDateETC = dateObjectETC.toLocaleDateString('en-US', {
year: 'numeric',
month: 'long',
day: 'numeric',
});
const formattedTimeETC = dateObjectETC.toLocaleTimeString('en-US', {
hour: '2-digit',
minute: '2-digit',
timeZoneName: 'short',
});
const formattedTimeUTC = dateObjectUTC.toLocaleTimeString('en-US', {
hour: '2-digit',
minute: '2-digit',
timeZoneName: 'short',
});
const counter = index + 1;
return `# \`Commit nº ${counter}\`\n## AUTHOR × DATE\n* **${item.author}** ( _${item.username}_ )\n* **${formattedDateETC}** @ ${formattedTimeETC} (${formattedTimeUTC})\n## MESSAGE\n\`\`\`\n${item.message}\n\`\`\`\n## FILES CHANGED\n> ### ${item.html_url}\n\n\`\`\`\n${item.html_url}\n\`\`\`\n---\n`;
}).join('\n');
core.setOutput('extracted_data', formattedExtractedData);
core.setOutput('condition_met', 'true');
} else {
core.setOutput('extracted_data', '');
core.setOutput('condition_met', 'false');
}
- name: Create Issue
if: steps.process_json.outputs.condition_met == 'true'
uses: dacbd/[email protected]
with:
token: ${{ secrets.GENERIC_ACTION_REPO_SCOPE }}
title: ${{ steps.dates.outputs.today }} — ${{ steps.process_json.outputs.commits_length }} new commit(s) made to `${{ env.REMOTE_REPO_FILE_TO_CHECK }}` in ${{ env.REMOTE_REPO_OWNER }}'s ${{ env.REMOTE_REPO_NAME }} repo.
body: |
${{ steps.process_json.outputs.extracted_data }}
assignees: ${{ env.ASSIGNED }}
labels: ${{ env.ISSUE_LABELS_TO_APPLY }}