|
| 1 | +// ArcGIS Portal REST API — Search reference: |
| 2 | +// https://developers.arcgis.com/rest/users-groups-and-items/search-reference.htm |
| 3 | +const API_URL = |
| 4 | + 'https://geoportal.un.org/arcgis/sharing/rest/search?f=json&q=(type:%22geojson%22)%20AND%20(title:%22*geodata*%22)&sortField=modified&sortOrder=desc'; |
| 5 | + |
| 6 | +export default async function checkUnGeodata({ github, context, core }) { |
| 7 | + // Fetch the UN Geodata API |
| 8 | + const res = await fetch(API_URL); |
| 9 | + if (!res.ok) throw new Error(`API request failed: ${res.status}`); |
| 10 | + const data = await res.json(); |
| 11 | + const newest = data.results[0]; |
| 12 | + if (!newest) throw new Error('No results returned from API'); |
| 13 | + |
| 14 | + const marker = `<!-- un-geodata-modified:${newest.modified} -->`; |
| 15 | + |
| 16 | + // Check if we already created an issue for this modified timestamp |
| 17 | + const { data: issues } = await github.rest.issues.listForRepo({ |
| 18 | + owner: context.repo.owner, |
| 19 | + repo: context.repo.repo, |
| 20 | + labels: 'topojson', |
| 21 | + state: 'all', |
| 22 | + sort: 'created', |
| 23 | + direction: 'desc', |
| 24 | + per_page: 100 |
| 25 | + }); |
| 26 | + |
| 27 | + if (issues.some((issue) => issue.body?.includes(marker))) { |
| 28 | + core.info('No new updates — issue already exists for this timestamp'); |
| 29 | + return; |
| 30 | + } |
| 31 | + |
| 32 | + // Build the issue body |
| 33 | + const summary = data.results |
| 34 | + .map((r) => { |
| 35 | + const date = new Date(r.modified).toISOString().slice(0, 10); |
| 36 | + return `- **${r.title}** (modified: ${date}, id: \`${r.id}\`)`; |
| 37 | + }) |
| 38 | + .join('\n'); |
| 39 | + |
| 40 | + const body = [ |
| 41 | + marker, |
| 42 | + '', |
| 43 | + `The [UN Geoportal geodata API](${API_URL}) has new or updated artifacts.`, |
| 44 | + '', |
| 45 | + `### Datasets found (${data.total}):`, |
| 46 | + summary, |
| 47 | + '', |
| 48 | + '### Next steps', |
| 49 | + '- Review the updated dataset at the [UN Geoportal](https://geoportal.un.org/)', |
| 50 | + '- Determine if `topojson/` sources need updating', |
| 51 | + '', |
| 52 | + '---', |
| 53 | + `*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.*` |
| 54 | + ].join('\n'); |
| 55 | + |
| 56 | + await github.rest.issues.create({ |
| 57 | + owner: context.repo.owner, |
| 58 | + repo: context.repo.repo, |
| 59 | + title: `UN Geodata update detected: ${newest.title}`, |
| 60 | + body, |
| 61 | + labels: ['topojson'] |
| 62 | + }); |
| 63 | +} |
0 commit comments