Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions .github/scripts/check-un-geodata.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// ArcGIS Portal REST API — Search reference:
// https://developers.arcgis.com/rest/users-groups-and-items/search-reference.htm
const API_URL =
'https://geoportal.un.org/arcgis/sharing/rest/search?f=json&q=(type:%22geojson%22)%20AND%20(title:%22*geodata*%22)&sortField=modified&sortOrder=desc';

export default async function checkUnGeodata({ github, context, core }) {
// Fetch the UN Geodata API
const res = await fetch(API_URL);
if (!res.ok) throw new Error(`API request failed: ${res.status}`);
const data = await res.json();
const newest = data.results[0];
if (!newest) throw new Error('No results returned from API');

const marker = `<!-- un-geodata-modified:${newest.modified} -->`;

// Check if we already created an issue for this modified timestamp
const { data: issues } = await github.rest.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
labels: 'topojson',
state: 'all',
sort: 'created',
direction: 'desc',
per_page: 100
});

if (issues.some((issue) => issue.body?.includes(marker))) {
core.info('No new updates — issue already exists for this timestamp');
return;
}

// Build the issue body
const summary = data.results
.map((r) => {
const date = new Date(r.modified).toISOString().slice(0, 10);
return `- **${r.title}** (modified: ${date}, id: \`${r.id}\`)`;
})
.join('\n');

const body = [
marker,
'',
`The [UN Geoportal geodata API](${API_URL}) has new or updated artifacts.`,
'',
`### Datasets found (${data.total}):`,
summary,
'',
'### Next steps',
'- Review the updated dataset at the [UN Geoportal](https://geoportal.un.org/)',
'- Determine if `topojson/` sources need updating',
'',
'---',
`*This issue was created automatically by the [Check UN Geodata Updates](${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/workflows/check-un-geodata.yml) workflow.*`
].join('\n');

await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: `UN Geodata update detected: ${newest.title}`,
body,
labels: ['topojson']
});
}
25 changes: 25 additions & 0 deletions .github/workflows/check-un-geodata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Check UN Geodata Updates

on:
schedule:
# First day of every month at 09:00 UTC
- cron: '0 9 1 * *'
workflow_dispatch:

permissions:
issues: write

jobs:
check-geodata:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
sparse-checkout: .github/scripts

- name: Check for UN Geodata updates
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7
with:
script: |
const { default: checkUnGeodata } = await import('${{ github.workspace }}/.github/scripts/check-un-geodata.mjs');
await checkUnGeodata({ github, context, core });
Loading