@nswds/tokens 2.1.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,115 @@
1
+ name: AI PR Title Generator
2
+
3
+ on:
4
+ pull_request:
5
+ types: [opened, reopened, synchronize, edited]
6
+
7
+ jobs:
8
+ generate-title:
9
+ runs-on: ubuntu-latest
10
+
11
+ permissions:
12
+ contents: read # Required to fetch commits
13
+ pull-requests: write # Required to update PR title
14
+
15
+ steps:
16
+ - name: Checkout code
17
+ uses: actions/checkout@v4
18
+ with:
19
+ fetch-depth: 0 # Fetch full history for commit diffing
20
+
21
+ - name: Debug Git Remote
22
+ run: |
23
+ echo "🔍 Verifying Git Remote"
24
+ git remote -v
25
+ echo "🔍 Listing refs from origin"
26
+ git ls-remote origin
27
+
28
+ - name: Get commit messages
29
+ id: commits
30
+ run: |
31
+ COMMITS=$(git log origin/${{ github.base_ref }}..HEAD --pretty=format:"%s" | grep -E "^(feat|fix|docs|style|refactor|test|chore|build|ci|perf)(\(.*\))?: " || echo "")
32
+ echo "commits<<EOF" >> $GITHUB_OUTPUT
33
+ echo "$COMMITS" >> $GITHUB_OUTPUT
34
+ echo "EOF" >> $GITHUB_OUTPUT
35
+
36
+ - name: Get Current PR Title
37
+ id: get-pr-title
38
+ uses: actions/github-script@v7
39
+ with:
40
+ script: |
41
+ const { data: pr } = await github.rest.pulls.get({
42
+ owner: context.repo.owner,
43
+ repo: context.repo.repo,
44
+ pull_number: context.issue.number
45
+ });
46
+ console.log(`Current PR title: "${pr.title}"`);
47
+ core.setOutput("pr_title", pr.title);
48
+
49
+ - name: Generate PR title with OpenAI
50
+ id: ai
51
+ if: ${{ steps.commits.outputs.commits != '' }}
52
+ run: |
53
+ COMMIT_LIST="${{ steps.commits.outputs.commits }}"
54
+ echo "📝 Commit messages detected:"
55
+ echo "$COMMIT_LIST"
56
+
57
+ JSON_PAYLOAD=$(jq -n \
58
+ --arg commits "$COMMIT_LIST" \
59
+ '{
60
+ model: "gpt-4",
61
+ messages: [
62
+ {
63
+ role: "system",
64
+ content: "You are an AI assistant that generates PR titles following the Conventional Commits specification (https://www.conventionalcommits.org/en/v1.0.0/)."
65
+ },
66
+ {
67
+ role: "user",
68
+ content: "Here are the commit messages:\n\n\($commits)\n\nGenerate a clear, informative PR title following the Conventional Commits format. Pick the most appropriate type (feat, fix, chore, etc.), include a scope if relevant, and summarize concisely. Return only the title, nothing else."
69
+ }
70
+ ],
71
+ temperature: 0.4
72
+ }')
73
+
74
+ RESPONSE=$(curl -s https://api.openai.com/v1/chat/completions \
75
+ -H "Authorization: Bearer ${{ secrets.OPENAI_API_KEY }}" \
76
+ -H "Content-Type: application/json" \
77
+ -d "$JSON_PAYLOAD")
78
+
79
+ TITLE=$(echo "$RESPONSE" | jq -r '.choices[0].message.content' | head -n 1)
80
+ echo "title=$TITLE" >> $GITHUB_OUTPUT
81
+
82
+ - name: Validate PR Title
83
+ id: validate-title
84
+ run: |
85
+ PR_TITLE="${{ steps.get-pr-title.outputs.pr_title }}"
86
+ AI_TITLE="${{ steps.ai.outputs.title }}"
87
+
88
+ # Regex for Conventional Commits format
89
+ CONVENTIONAL_COMMIT_REGEX="^(feat|fix|docs|style|refactor|test|chore|build|ci|perf)(\(.*\))?: .+"
90
+
91
+ echo "🔍 Current PR Title: $PR_TITLE"
92
+ echo "🧠 Suggested AI PR Title: $AI_TITLE"
93
+
94
+ if [[ -z "$PR_TITLE" || ! "$PR_TITLE" =~ $CONVENTIONAL_COMMIT_REGEX ]]; then
95
+ echo "❌ PR Title is missing or not in Conventional Commits format."
96
+ echo "✅ Using AI-generated title: $AI_TITLE"
97
+ echo "update_needed=true" >> $GITHUB_ENV
98
+ else
99
+ echo "✅ PR Title is already valid."
100
+ echo "update_needed=false" >> $GITHUB_ENV
101
+ fi
102
+
103
+ - name: Update PR Title if Invalid or Empty
104
+ if: env.update_needed == 'true'
105
+ uses: actions/github-script@v7
106
+ with:
107
+ script: |
108
+ const title = `${{ steps.ai.outputs.title }}`;
109
+ await github.rest.pulls.update({
110
+ owner: context.repo.owner,
111
+ repo: context.repo.repo,
112
+ pull_number: context.issue.number,
113
+ title: title
114
+ });
115
+ console.log(`✅ PR title updated to: "${title}"`);
@@ -2,8 +2,6 @@ name: 'OpenCommit Action'
2
2
 
3
3
  on:
4
4
  push:
5
- # this list of branches is often enough,
6
- # but you may still ignore other public branches
7
5
  branches-ignore: [main master dev development release]
8
6
 
9
7
  jobs:
@@ -25,10 +23,7 @@ jobs:
25
23
  GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
26
24
 
27
25
  env:
28
- # set openAI api key in repo actions secrets,
29
- # for openAI keys go to: https://platform.openai.com/account/api-keys
30
- # for repo secret go to: <your_repo_url>/settings/secrets/actions
31
- OCO_API_KEY: ${{ secrets.OPENAI_API_KEY }}
26
+ OCO_OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
32
27
 
33
28
  # customization
34
29
  OCO_TOKENS_MAX_INPUT: 4096
@@ -38,4 +33,4 @@ jobs:
38
33
  OCO_EMOJI: false
39
34
  OCO_MODEL: gpt-4o
40
35
  OCO_LANGUAGE: en
41
- OCO_PROMPT_MODULE: conventional-commit
36
+ OCO_PROMPT_MODULE: conventional-commit
@@ -0,0 +1,21 @@
1
+ # .github/workflows/validate-branch-name.yml
2
+ name: Validate Branch Name
3
+
4
+ on:
5
+ pull_request:
6
+ types: [opened, edited, reopened]
7
+
8
+ jobs:
9
+ check-branch-name:
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ - name: Check branch name
13
+ run: |
14
+ BRANCH_NAME="${{ github.head_ref }}"
15
+ echo "Branch name: $BRANCH_NAME"
16
+ if [[ ! "$BRANCH_NAME" =~ ^(feature|bugfix|hotfix|release|docs|build|test|refactor|chore)(/(issue|ticket)/[A-Za-z0-9_-]+)?/[a-z0-9-]+$ ]]; then
17
+ echo "❌ Branch name '$BRANCH_NAME' does not follow naming convention."
18
+ exit 1
19
+ fi
20
+ echo "✅ Branch name '$BRANCH_NAME' follows naming convention."
21
+
package/CHANGELOG.md CHANGED
@@ -1,21 +1,23 @@
1
- # [2.1.0](https://github.com/digitalnsw/nswds-tokens/compare/v2.0.0...v2.1.0) (2025-03-25)
1
+ # [2.2.0](https://github.com/digitalnsw/nswds-tokens/compare/v2.1.1...v2.2.0) (2025-03-27)
2
2
 
3
3
 
4
4
  ### Features
5
5
 
6
- * **workflow:** add OpenCommit GitHub Action workflow for automated commit messages generation ([5ba4c6c](https://github.com/digitalnsw/nswds-tokens/commit/5ba4c6cf9e429f4776c6ade072adf1fe9818fd69))
6
+ * **github:** add branch name validation workflow to enforce naming conventions ([dafc071](https://github.com/digitalnsw/nswds-tokens/commit/dafc0717ffdf394ca404e4d5a15831d76d241329))
7
+ * **workflows:** add AI PR title generator workflow to automate PR title suggestions based on commit messages ([f717d26](https://github.com/digitalnsw/nswds-tokens/commit/f717d26f939b5dbdc3e8ed19f751f02224e8ab49))
8
+
9
+ ## [2.1.1](https://github.com/digitalnsw/nswds-tokens/compare/v2.1.0...v2.1.1) (2025-03-25)
10
+
11
+ ### Bug Fixes
7
12
 
8
- # 1.0.0 (2025-03-25)
13
+ - **workflow:** rename environment variable OCO_API_KEY to OCO_OPENAI_API_KEY for clarity and consistency ([6c162b1](https://github.com/digitalnsw/nswds-tokens/commit/6c162b1e0c7d0509321d064d3c18d2bf00428dd7))
14
+ - **workflow:** rename OCO_API_KEY to OCO_OPENAI_API_KEY for clarity ([b980c42](https://github.com/digitalnsw/nswds-tokens/commit/b980c425dbc69e940b8e71fd60d142d2570c57ef))
15
+
16
+ # [2.1.0](https://github.com/digitalnsw/nswds-tokens/compare/v2.0.0...v2.1.0) (2025-03-25)
9
17
 
10
18
  ### Features
11
19
 
12
- - add GitHub Actions workflow for autofilling PR descriptions ([6304e82](https://github.com/digitalnsw/nswds-tokens/commit/6304e822759e8ebd60bc146f5871e7eaf31bcaee))
13
- - add GitHub Actions workflow for automated releases and semantic-release configuration ([0b600a1](https://github.com/digitalnsw/nswds-tokens/commit/0b600a1e1d398e17bfc1ebbd7837d77bb614d015))
14
- - **colors:** add new color definitions for various themes in hex, hsl, oklch, and rgb formats to enhance design consistency across the application ([74b4def](https://github.com/digitalnsw/nswds-tokens/commit/74b4defec3d7e552de453852b14de47d157c38e6))
15
- - **colors:** add new color definitions in hex, hsl, oklch, and rgb formats for global and masterbrand themes to enhance design consistency across the application ([a113b2d](https://github.com/digitalnsw/nswds-tokens/commit/a113b2daccbf67ecfc66c96fb77b3c772f17eb3a))
16
- - **release:** add GitHub Actions workflow for automated releases on main branch ([8ebd9f3](https://github.com/digitalnsw/nswds-tokens/commit/8ebd9f37003af25caaba62f97f455ce07bcc93fa))
17
- - **release:** add GitHub Actions workflow for automated releases on main branch ([0ad84c0](https://github.com/digitalnsw/nswds-tokens/commit/0ad84c0d3676006be55e519d425cbae499174dd3))
18
- - **tokens:** add new color tokens in various formats (json, js, css, scss, less) for improved design consistency across the application ([c8cf2d9](https://github.com/digitalnsw/nswds-tokens/commit/c8cf2d9e4eab87b9ec026e92a80067a28fbb7e30))
20
+ - **workflow:** add OpenCommit GitHub Action workflow for automated commit messages generation ([5ba4c6c](https://github.com/digitalnsw/nswds-tokens/commit/5ba4c6cf9e429f4776c6ade072adf1fe9818fd69))
19
21
 
20
22
  # 2.0.0 (2025-03-24)
21
23
 
package/README.md CHANGED
@@ -1,3 +0,0 @@
1
- # nswds-tokens
2
-
3
- NSW Design System Application Kit Design Tokens
@@ -0,0 +1,29 @@
1
+ #!/bin/bash
2
+
3
+ # Allowed types
4
+ ALLOWED_TYPES="feature|bugfix|hotfix|release|docs|build|test|refactor|chore"
5
+
6
+ # Check if a branch name was provided
7
+ if [ -z "$1" ]; then
8
+ echo "❌ Please provide a branch name."
9
+ echo "Usage: ./create-branch.sh {branch-name}"
10
+ exit 1
11
+ fi
12
+
13
+ branch_name=$1
14
+
15
+ # Regex pattern
16
+ pattern="^(${ALLOWED_TYPES})(/(issue|ticket)/[A-Za-z0-9_-]+)?/[a-z0-9-]+$"
17
+
18
+ # Check against pattern
19
+ if [[ $branch_name =~ $pattern ]]; then
20
+ git checkout -b "$branch_name"
21
+ echo "✅ Branch '$branch_name' created."
22
+ git push -u origin "$branch_name"
23
+ echo "✅ Branch '$branch_name' pushed to remote."
24
+ else
25
+ echo "❌ Branch name '$branch_name' does not follow naming convention."
26
+ echo "✅ Format: {type}[/issue/{number} | /ticket/{id}]/{short-description}"
27
+ echo "📌 Allowed types: $ALLOWED_TYPES"
28
+ exit 1
29
+ fi
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nswds/tokens",
3
- "version": "2.1.0",
3
+ "version": "2.2.0",
4
4
  "description": "NSW Design System Application Kit Design Tokens",
5
5
  "homepage": "https://github.com/digitalnsw/nswds-tokens#readme",
6
6
  "repository": {
@@ -0,0 +1,61 @@
1
+ #!/bin/bash
2
+
3
+ # Ensure API key is set
4
+ if [ -z "$OPENAI_API_KEY" ]; then
5
+ echo "❌ Please set your OPENAI_API_KEY environment variable."
6
+ exit 1
7
+ fi
8
+
9
+ # Set model and endpoint
10
+ MODEL="gpt-4"
11
+ ENDPOINT="https://api.openai.com/v1/chat/completions"
12
+
13
+ # Get current branch and base branch
14
+ branch=$(git rev-parse --abbrev-ref HEAD)
15
+ default_branch=$(git remote show origin | grep 'HEAD branch' | awk '{print $NF}')
16
+
17
+ # Extract commits from current branch
18
+ commits=$(git log "$default_branch"..HEAD --pretty=format:"%s" | grep -E "^(feat|fix|docs|style|refactor|test|chore|build|ci|perf)(\(.*\))?: ")
19
+
20
+ if [ -z "$commits" ]; then
21
+ echo "❌ No Conventional Commits found on this branch."
22
+ exit 1
23
+ fi
24
+
25
+ # Prepare JSON payload with Conventional Commit title prompt
26
+ messages=$(jq -n \
27
+ --arg commits "$commits" \
28
+ '[
29
+ {
30
+ "role": "system",
31
+ "content": "You are an assistant that writes pull request titles in the Conventional Commits format (https://www.conventionalcommits.org/en/v1.0.0/)."
32
+ },
33
+ {
34
+ "role": "user",
35
+ "content": "Here are the commit messages:\n\n\($commits)\n\nWrite a concise PR title that summarizes the changes and follows the Conventional Commits format. Use an appropriate type (e.g., feat, fix, chore) and include a scope in parentheses if applicable. Return only the title and nothing else."
36
+ }
37
+ ]'
38
+ )
39
+
40
+ # Call OpenAI API
41
+ response=$(curl -s "$ENDPOINT" \
42
+ -H "Authorization: Bearer $OPENAI_API_KEY" \
43
+ -H "Content-Type: application/json" \
44
+ -d "{\"model\": \"$MODEL\", \"messages\": $messages, \"temperature\": 0.4}"
45
+ )
46
+
47
+ # Extract and display title
48
+ title=$(echo "$response" | jq -r '.choices[0].message.content' | head -n 1)
49
+
50
+ echo ""
51
+ echo "✅ Suggested PR title from OpenAI:"
52
+ echo "$title"
53
+ echo ""
54
+
55
+ # Optionally prompt to confirm and create PR
56
+ read -p "📝 Use this title to create the PR? [y/N]: " confirm
57
+ if [[ $confirm =~ ^[Yy]$ ]]; then
58
+ gh pr create --title "$title" --body "Auto-generated title using OpenAI" --head "$branch"
59
+ else
60
+ echo "🛑 PR not created. You can still copy and use the title manually."
61
+ fi