Project: AI Coding Coach #140
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
name: On Project Submitted | |
on: | |
issues: | |
types: | |
- opened | |
- edited | |
# workflow_dispatch: | |
# inputs: | |
# issue-number: | |
# description: 'Issue number' | |
# required: true | |
permissions: | |
contents: read | |
id-token: write | |
issues: write | |
pull-requests: write | |
jobs: | |
labelling: | |
name: 'Labelling' | |
runs-on: ubuntu-latest | |
steps: | |
# - name: Check event payload | |
# shell: pwsh | |
# run: | | |
# $eventPayload = ${{ toJson(github) }} | |
- name: Check issue details | |
id: issue | |
shell: bash | |
run: | | |
issueNumber=${{ github.event.issue.number }} | |
title=${{ toJSON(github.event.issue.title) }} | |
body=${{ toJSON(github.event.issue.body) }} | |
createdAt="${{ github.event.issue.created_at }}" | |
githubId="${{ github.event.issue.user.login }}" | |
assignee="${{ github.event.issue.assignee }}" | |
echo "issueNumber=$issueNumber" >> $GITHUB_OUTPUT | |
echo "title=$title" >> $GITHUB_OUTPUT | |
echo "body=$body" >> $GITHUB_OUTPUT | |
echo "createdAt=$createdAt" >> $GITHUB_OUTPUT | |
echo "githubId=$githubId" >> $GITHUB_OUTPUT | |
echo "assignee=$assignee" >> $GITHUB_OUTPUT | |
- name: Vaildate issue - project submission | |
id: project | |
shell: pwsh | |
run: | | |
$body = $(@" | |
${{ steps.issue.outputs.body }} | |
"@).Replace("`"", "\`"") | |
$isValid = $($body -match '^### Project name').ToString().ToLowerInvariant() | |
echo "isValid=$isValid" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf-8 -Append | |
$tz = [TimeZoneInfo]::FindSystemTimeZoneById("US/Pacific") | |
$dateSubmitted = [DateTimeOffset]::Parse("${{ steps.issue.outputs.createdAt }}") | |
$offset = $tz.GetUtcOffset($dateSubmitted) | |
$dateSubmitted = $dateSubmitted.ToOffset($offset) | |
$dateDue = $([DateTimeOffset]::Parse("${{ vars.SUBMISSION_DUE_DATE }}")) | |
$isOverdue = "$($dateSubmitted -gt $dateDue)".ToLowerInvariant() | |
$dateSubmittedValue = $dateSubmitted.ToString("yyyy-MM-ddTHH:mm:ss.fffzzz") | |
$dateDueValue = $dateDue.ToString("yyyy-MM-ddTHH:mm:ss.fffzzz") | |
echo "dateSubmitted=$dateSubmittedValue" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf-8 -Append | |
echo "dateDue=$dateDueValue" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf-8 -Append | |
echo "isOverdue=$isOverdue" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf-8 -Append | |
- name: Comment to issue - Overdue | |
if: steps.project.outputs.isValid == 'true' && steps.project.outputs.isOverdue == 'true' | |
uses: actions-cool/issues-helper@v3 | |
with: | |
actions: 'create-comment' | |
token: ${{ secrets.GITHUB_TOKEN }} | |
issue-number: ${{ steps.issue.outputs.issueNumber }} | |
body: | | |
Hey, @${{ steps.issue.outputs.githubId }} | |
* Submitted: ${{ steps.project.outputs.dateSubmitted }} | |
* Due: ${{ steps.project.outputs.dateDue }} | |
Unfortunately, your submission is overdue, so we can't accept yours. | |
- name: Add label - Overdue | |
if: steps.project.outputs.isValid == 'true' && steps.project.outputs.isOverdue == 'true' | |
uses: actions-cool/issues-helper@v3 | |
with: | |
actions: 'add-labels' | |
token: ${{ secrets.GITHUB_TOKEN }} | |
issue-number: ${{ steps.issue.outputs.issueNumber }} | |
labels: 'overdue' | |
- name: Close issue - Overdue | |
if: steps.project.outputs.isValid == 'true' && steps.project.outputs.isOverdue == 'true' | |
uses: actions-cool/issues-helper@v3 | |
with: | |
actions: 'close-issue' | |
token: ${{ secrets.GITHUB_TOKEN }} | |
issue-number: ${{ steps.issue.outputs.issueNumber }} | |
- name: Check project details | |
if: steps.project.outputs.isValid == 'true' && steps.project.outputs.isOverdue == 'false' | |
id: projectDetails | |
shell: pwsh | |
run: | | |
$body = $(@" | |
${{ steps.issue.outputs.body }} | |
"@).Replace("`"", "\`"") | |
$body -match '### Project Repository URL(?<url>.+)### Project video' | |
$projectRepositoryUrl = $Matches.url.Replace("\r", "").Replace("\n", "") | |
echo "repositoryUrl=$projectRepositoryUrl" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf-8 -Append | |
$body -match '### Project video(?<url>.+)### Team members' | |
$projectVideoUrl = $Matches.url.Replace("\r", "").Replace("\n", "") | |
echo "videoUrl=$projectVideoUrl" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf-8 -Append | |
- name: Vaildate project details | |
if: steps.project.outputs.isValid == 'true' && steps.project.outputs.isOverdue == 'false' | |
id: validation | |
shell: pwsh | |
run: | | |
$isValidRepositoryUrl = $("${{ steps.projectDetails.outputs.repositoryUrl }}".StartsWith("https://github.com")).ToString().ToLowerInvariant() | |
$isValidVideoUrl = $("${{ steps.projectDetails.outputs.videoUrl }}" -match '(^(https:\/\/)?(www\.)?(youtube\.com|youtu\.be)|^https:\/\/github\.com.*\.mp4$)').ToString().ToLowerInvariant() | |
echo "isValidRepositoryUrl=$isValidRepositoryUrl" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf-8 -Append | |
echo "isValidVideoUrl=$isValidVideoUrl" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf-8 -Append | |
Write-Host $isValidVideoUrl | |
Write-Host ${{ steps.projectDetails.outputs.videoUrl }} | |
- name: Add label - Under review | |
if: steps.project.outputs.isValid == 'true' && steps.project.outputs.isOverdue == 'false' | |
uses: actions-cool/issues-helper@v3 | |
with: | |
actions: 'add-labels' | |
token: ${{ secrets.GITHUB_TOKEN }} | |
issue-number: ${{ steps.issue.outputs.issueNumber }} | |
labels: 'under review' | |
- name: Add label - Invalid project repository URL | |
if: steps.project.outputs.isValid == 'true' && steps.project.outputs.isOverdue == 'false' && steps.validation.outputs.isValidRepositoryUrl == 'false' | |
uses: actions-cool/issues-helper@v3 | |
with: | |
actions: 'add-labels' | |
token: ${{ secrets.GITHUB_TOKEN }} | |
issue-number: ${{ steps.issue.outputs.issueNumber }} | |
labels: 'invalid:project' | |
- name: Add label - Invalid video URL | |
if: steps.project.outputs.isValid == 'true' && steps.project.outputs.isOverdue == 'false' && steps.validation.outputs.isValidVideoUrl == 'false' | |
uses: actions-cool/issues-helper@v3 | |
with: | |
actions: 'add-labels' | |
token: ${{ secrets.GITHUB_TOKEN }} | |
issue-number: ${{ steps.issue.outputs.issueNumber }} | |
labels: 'invalid:video' |