[wg/immersive-web] Immersive Web WG 2026 Group Charter #71
This file contains hidden or 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: Auto Label and Link Related Issues | |
| on: | |
| issues: | |
| types: [opened] | |
| jobs: | |
| label-and-link: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Extract shortname, add label, and link related issues | |
| uses: actions/github-script@v6 | |
| with: | |
| script: | | |
| const issueBody = context.payload.issue.body || ""; | |
| const issueNumber = context.payload.issue.number; | |
| // 允许 shortname: [ value ] 这种格式,并支持符号 | |
| const match = issueBody.match(/shortname:\s*\[?\s*([\w\-.:/]+)\s*\]?/i); | |
| if (match && match[1]) { | |
| const shortname = match[1].trim(); // 去除额外空格 | |
| const labelName = `s:${shortname}`; | |
| const labelColor = "6bc5c6"; | |
| // 获取当前 repo 的所有标签 | |
| let existingLabel = false; | |
| try { | |
| const labels = await github.rest.issues.listLabelsForRepo({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| per_page: 100 | |
| }); | |
| existingLabel = labels.data.some(label => label.name === labelName); | |
| } catch (error) { | |
| console.error("Failed to fetch labels:", error.message); | |
| } | |
| // 如果标签不存在,则创建 | |
| if (!existingLabel) { | |
| try { | |
| await github.rest.issues.createLabel({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| name: labelName, | |
| color: labelColor, | |
| description: `Automatically created label for shortname: ${shortname}`, | |
| }); | |
| console.log(`Label '${labelName}' created with color #${labelColor}.`); | |
| } catch (error) { | |
| console.error(`Failed to create label: ${error.message}`); | |
| } | |
| } else { | |
| console.log(`Label '${labelName}' already exists.`); | |
| } | |
| // 给 Issue 添加标签 | |
| try { | |
| await github.rest.issues.addLabels({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: issueNumber, | |
| labels: [labelName], | |
| }); | |
| console.log(`Label '${labelName}' added to issue #${issueNumber}.`); | |
| } catch (error) { | |
| console.error(`Failed to add label: ${error.message}`); | |
| } | |
| // 查找 w3c/apa-review 仓库中是否有相同标签的 issue | |
| try { | |
| const relatedIssues = await github.rest.issues.listForRepo({ | |
| owner: "w3c", | |
| repo: "apa-review", | |
| state: "open", | |
| labels: [labelName], | |
| per_page: 10 | |
| }); | |
| if (relatedIssues.data.length > 0) { | |
| const relatedLinks = relatedIssues.data | |
| .map(issue => `- [#${issue.number}](${issue.html_url}): ${issue.title}`) | |
| .join("\n"); | |
| const commentBody = `Related issue from APA WG:\n${relatedLinks}`; | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: issueNumber, | |
| body: commentBody, | |
| }); | |
| console.log(`Added comment linking related issues from w3c/apa-review.`); | |
| } else { | |
| console.log(`No related issues found in w3c/apa-review.`); | |
| } | |
| } catch (error) { | |
| console.error(`Failed to fetch related issues: ${error.message}`); | |
| } | |
| } else { | |
| console.log("No shortname found in the issue body."); | |
| } |