name: 'Grasp issue dependencies' description: 'Help project managers and project owners with easy-to-understand views of github issue dependencies.' inputs: label: description: 'Analyze the issue with the specified label' required: true github_token: description: 'GitHub Access Token' required: true runs: using: "composite" steps: - uses: actions/cache@v3 with: path: | ~/.cargo/bin/ ~/.cargo/registry/index/ ~/.cargo/registry/cache/ ~/.cargo/git/db/ target/ key: ${{ runner.os }}-cargo-${{ hashFiles('~/.cargo/bin/gid') }}-0.1.3 - name: Install gid shell: bash run: | cargo -vV cargo install --version 0.1.3 gid_cli || true - uses: actions/github-script@v6 env: LABEL: '${{ inputs.label }}' GITHUB_ACCESS_TOKEN: ${{ inputs.github_token }} with: script: | const query = ` query ($owner: String!, $name: String!, $label: String!) { repository(owner: $owner, name: $name) { issues(first: 100, labels: [$label], states: OPEN) { nodes { number } } } }`; const {LABEL} = process.env const variables = { owner: context.repo.owner, name: context.repo.repo, label: LABEL } const result = await github.graphql(query, variables) for (const issue of result.repository.issues.nodes) { const query = ` query ($owner: String!, $name: String!, $number: Int!) { repository(owner: $owner, name: $name) { issue(number: $number) { comments(first: 100) { nodes { databaseId body } } } } }`; const variables = { owner: context.repo.owner, name: context.repo.repo, number: issue.number } const result = await github.graphql(query, variables) let id = null; for (const comment of result.repository.issue.comments.nodes) { if(comment.body.includes("/generate_gid")) { id = comment.databaseId } } const { exec } = require("child_process"); const command = `gid -o ${context.repo.owner} -r ${context.repo.repo} -i ${issue.number}` exec(command, (error, stdout, stderr) => { if (error) { console.log(`error: ${error.message}`); return; } if (stderr) { console.log(`stderr: ${stderr}`); return; } const mermaid = `${stdout}`; if (id === null) { console.log("add new comment", mermaid); github.rest.issues.createComment({ issue_number: issue.number, owner: context.repo.owner, repo: context.repo.repo, body: `/generate_gid\n${mermaid}` }) } else { console.log("update comment", mermaid); github.rest.issues.updateComment({ comment_id: id, owner: context.repo.owner, repo: context.repo.repo, body: `/generate_gid\n${mermaid}` }) } }); }