Skip to content

Build a CAP Application : Demo Tutorial env updated to latest CDS Version 5 #2

Build a CAP Application : Demo Tutorial env updated to latest CDS Version 5

Build a CAP Application : Demo Tutorial env updated to latest CDS Version 5 #2

name: Assign Tutorial Author to Issue
# Triggers when a label is added to an issue.
# The existing label-issues.yml workflow auto-applies a "tutorial:<slug>"
# label when a new issue is opened, which in turn fires this workflow.
on:
issues:
types:
- labeled
jobs:
assign-author:
runs-on: ubuntu-latest
# Only run when the added label matches the "tutorial:*" pattern
if: startsWith(github.event.label.name, 'tutorial:')
steps:
- name: Check out repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Full history needed for git log fallback
- name: Resolve tutorial author and assign to issue
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
LABEL_NAME: ${{ github.event.label.name }}
ISSUE_NUMBER: ${{ github.event.issue.number }}
REPO: ${{ github.repository }}
run: |
set -e
# Extract slug from label, e.g. "tutorial:btp-app-logging" -> "btp-app-logging"
SLUG="${LABEL_NAME#tutorial:}"
echo "Tutorial slug: $SLUG"
TUTORIAL_FILE="tutorials/${SLUG}/${SLUG}.md"
if [ ! -f "$TUTORIAL_FILE" ]; then
echo "Tutorial file not found: $TUTORIAL_FILE — skipping assignment."
exit 0
fi
# Parse author_profile from YAML frontmatter
AUTHOR_PROFILE=$(grep -m1 "^author_profile:" "$TUTORIAL_FILE" | sed 's/author_profile:[[:space:]]*//' | tr -d '[:space:]')
# Extract GitHub username from URL (last path segment)
GITHUB_USERNAME=$(echo "$AUTHOR_PROFILE" | sed 's|https://github.com/||' | tr -d '/')
if [ -z "$GITHUB_USERNAME" ]; then
echo "No author_profile found — falling back to last git committer for tutorials/${SLUG}/"
GITHUB_USERNAME=$(git log -1 --pretty="%an" -- "tutorials/${SLUG}/")
if [ -z "$GITHUB_USERNAME" ]; then
echo "No git history found for tutorials/${SLUG}/ — skipping assignment."
exit 0
fi
echo "Last committer: $GITHUB_USERNAME"
fi
echo "Assigning @${GITHUB_USERNAME} to issue #${ISSUE_NUMBER}"
# Assign the resolved user to the issue via GitHub REST API
HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" \
-X POST \
-H "Authorization: Bearer $GITHUB_TOKEN" \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/${REPO}/issues/${ISSUE_NUMBER}/assignees" \
-d "{\"assignees\": [\"${GITHUB_USERNAME}\"]}")
if [ "$HTTP_STATUS" -eq 201 ]; then
echo "Successfully assigned @${GITHUB_USERNAME} to issue #${ISSUE_NUMBER}."
else
echo "Assignment API returned HTTP ${HTTP_STATUS} — the user may not be a repo collaborator."
fi