-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add global error handling. (#13)
* ci: update PR labelers. * feat: add global error handling.
- Loading branch information
Showing
11 changed files
with
287 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
name: Auto-label PR based on file paths | ||
|
||
on: | ||
pull_request: | ||
types: [opened, synchronize] | ||
|
||
jobs: | ||
label: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
pull-requests: write | ||
issues: write | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Label PR based on changes with colors | ||
uses: actions/github-script@v7 | ||
with: | ||
script: | | ||
const prFiles = await github.rest.pulls.listFiles({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
pull_number: context.issue.number | ||
}); | ||
// Define the labels and their colors | ||
const labelsToColor = { | ||
components: '1f77b4', // Blue - Components Related | ||
pages: 'ff7f0e', // Orange - Pages Related | ||
stores: '2ca02c', // Green - Stores Related (for Vuex or Pinia) | ||
server: '9467bd', // Purple - Server Related | ||
layouts: 'ffdd57', // Yellow - Layouts Related | ||
assets: 'd62728', // Red - Assets Related | ||
i18n: '8c564b', // Brown - i18n Related | ||
types: 'e377c2', // Pink - Types Related | ||
dependencies: 'e377c2', // Pink - Dependencies Related | ||
}; | ||
const labels = new Set(); | ||
const labelPaths = { | ||
components: 'components', | ||
pages: ['pages', 'app.vue'], | ||
stores: ['store', 'stores'], | ||
server: 'server', | ||
layouts: 'layouts', | ||
assets: ['public', 'assets'], | ||
i18n: 'i18n', | ||
types: 'types', | ||
dependencies: ['package.json', 'pnpm-lock.yaml'] | ||
}; | ||
prFiles.data.forEach(file => { | ||
Object.keys(labelPaths).forEach(label => { | ||
const paths = Array.isArray(labelPaths[label]) ? labelPaths[label] : [labelPaths[label]]; | ||
if (paths.some(path => file.filename.startsWith(path))) { | ||
labels.add(label); | ||
} | ||
}); | ||
}); | ||
if (labels.size > 0) { | ||
for (const label of labels) { | ||
try { | ||
// Check if the label exists | ||
await github.rest.issues.getLabel({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
name: label | ||
}); | ||
} catch (error) { | ||
// If label doesn't exist, create it with the specified color | ||
await github.rest.issues.createLabel({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
name: label, | ||
color: labelsToColor[label] || 'b0b0b0', // Use default gray if no color specified | ||
}); | ||
} | ||
} | ||
// Add labels to the PR | ||
await github.rest.issues.addLabels({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
issue_number: context.issue.number, | ||
labels: Array.from(labels) | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
name: size-label | ||
|
||
on: | ||
pull_request: | ||
types: [opened, synchronize] | ||
|
||
jobs: | ||
size-label: | ||
permissions: | ||
contents: read | ||
pull-requests: write | ||
issues: write | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: 🛎️ Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Determine PR size and add label | ||
id: size-label | ||
uses: pascalgn/[email protected] | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
IGNORED: | | ||
yarn.lock | ||
package-lock.json | ||
pnpm-lock.yaml | ||
package.json | ||
.pnp.* | ||
dist/ | ||
build/ | ||
.cache/ | ||
LICENSE | ||
with: | ||
sizes: > | ||
{ | ||
"0": "XS", | ||
"50": "S", | ||
"150": "M", | ||
"500": "L", | ||
"1000": "XL", | ||
"3000": "XXL" | ||
} | ||
- name: Set label colors | ||
uses: actions/github-script@v7 | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
script: | | ||
const labelsToColor = { | ||
'XS': 'd4c5f9', // Light purple | ||
'S': 'c2e0c6', // Light green | ||
'M': 'f9d0c4', // Light red | ||
'L': 'f7c6c7', // Light pink | ||
'XL': 'fef2c0', // Light yellow | ||
'XXL': 'e99695', // Light coral | ||
}; | ||
const sizeLabel = ${{ steps.size-label.outputs.sizeLabel }}; | ||
const color = labelsToColor[sizeLabel] || 'b0b0b0'; | ||
if (sizeLabel) { | ||
try { | ||
await github.rest.issues.updateLabel({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
name: sizeLabel, | ||
color: color, | ||
}); | ||
} catch (error) { | ||
// Label doesn't exist, create it | ||
await github.rest.issues.createLabel({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
name: sizeLabel, | ||
color: color, | ||
}); | ||
} | ||
} | ||
- name: Comment on large PRs | ||
if: ${{ contains('XL XXL', steps.size-label.outputs.sizeLabel) }} | ||
uses: actions/github-script@v7 | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
script: | | ||
await github.rest.issues.createComment({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
issue_number: context.issue.number, | ||
body: "This PR is too large and may need to be broken into smaller pieces." | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<template> | ||
<NuxtLayout name="default"> | ||
<div | ||
class="mx-8 mt-[30vh] flex flex-col items-center justify-center text-center" | ||
> | ||
<h1 class="mb-4 text-2xl font-bold text-tiaPink"> | ||
{{ | ||
error.statusCode === 404 | ||
? $t('error.notFound.title') | ||
: error.statusCode === 401 | ||
? $t('error.unauthorized.title') | ||
: $t('error.default.title') | ||
}} | ||
</h1> | ||
<p class="mb-6"> | ||
{{ | ||
error.statusCode === 404 | ||
? $t('error.notFound.description') | ||
: error.statusCode === 401 | ||
? $t('error.unauthorized.description') | ||
: $t('error.default.description') | ||
}} | ||
</p> | ||
<button | ||
class="rounded bg-tiaBlue px-4 py-2 text-white hover:bg-tiaBlue-dark" | ||
@click="$router.push('/')" | ||
> | ||
{{ $t('error.backToHome') }} | ||
</button> | ||
</div> | ||
</NuxtLayout> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import type { NuxtError } from '#app'; | ||
const _props = defineProps({ | ||
error: { | ||
type: Object as () => NuxtError, | ||
default: () => ({ statusCode: 500 }), | ||
}, | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<template> | ||
<div | ||
class="flex min-h-screen flex-col bg-light-background text-light-foreground dark:bg-dark-background dark:text-dark-foreground" | ||
> | ||
<UiProgressBar /> | ||
<UiBackToTop /> | ||
|
||
<LayoutSiteHeader /> | ||
<main class="container mx-auto max-w-7xl flex-grow px-4 py-8"> | ||
<slot /> | ||
</main> | ||
<LayoutSiteFooter /> | ||
</div> | ||
</template> |