Skip to content

Commit

Permalink
Post to Slack
Browse files Browse the repository at this point in the history
Signed-off-by: Jack Baldry <[email protected]>
  • Loading branch information
jdbaldry committed Oct 1, 2024
1 parent b17f0f4 commit 47666f4
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 7 deletions.
10 changes: 9 additions & 1 deletion .github/workflows/add-to-docs-project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,15 @@ jobs:
- run: yarn install
working-directory: ./add-to-docs-project

- run: node index.mjs
- id: add-to-docs-project
run: node index.mjs
env:
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
working-directory: ./add-to-docs-project

- name: Send Slack Message
id: slack
uses: grafana/shared-workflows/actions/send-slack-message@main
with:
channel-id: C05V6A36MB7
slack-message: ${{ steps.add-to-docs-project.outputs.added }}
10 changes: 8 additions & 2 deletions add-to-docs-project/index.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Octokit } from "@octokit/rest";
import process from "node:process";
import core from "@actions/core"; // Import the 'core' module
// gh api graphql -f query='
// query{
// organization(login: "grafana"){
Expand All @@ -10,6 +11,7 @@ import process from "node:process";
// }'
const PROJECT_ID = "PVT_kwDOAG3Mbc027w";
async function addIssuesToProject(repositories) {
const added = [];
try {
const octokit = new Octokit({
auth: process.env.GITHUB_TOKEN,
Expand All @@ -26,7 +28,8 @@ async function addIssuesToProject(repositories) {
since: twoHoursAgo.toISOString(),
});
for (const issue of issues) {
console.log(`Adding issue https://github.com/grafana/${repo}/issues/${issue.number} to the project if it's not there already.`);
console.log(`Adding issue ${issue.html_url} to the project if it's not there already.`);
added.push(issue.html_url);
const mutation = `mutation AddProjectItem($projectId: ID!, $contentId: ID!) {
addProjectV2ItemById(input: { projectId: $projectId, contentId: $contentId }) {
item {
Expand All @@ -43,7 +46,10 @@ async function addIssuesToProject(repositories) {
}
catch (error) {
console.error("Error adding issues to the project:", error.message);
core.setFailed(error.message);
}
return added;
}
const repositories = ["website", "writers-toolkit"];
addIssuesToProject(repositories);
const added = await addIssuesToProject(repositories);
core.setOutput("added", added.map((url) => `- ${url}`).join("\n"));
17 changes: 13 additions & 4 deletions add-to-docs-project/index.mts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { GraphQlQueryResponseData } from "@octokit/graphql";
import { Octokit } from "@octokit/rest";
import process from "node:process";
import core from "@actions/core"; // Import the 'core' module

// gh api graphql -f query='
// query{
Expand All @@ -12,7 +12,10 @@ import process from "node:process";
// }'
const PROJECT_ID = "PVT_kwDOAG3Mbc027w";

async function addIssuesToProject(repositories: Array<string>) {
async function addIssuesToProject(
repositories: Array<string>
): Promise<Array<string>> {
const added: Array<string> = [];
try {
const octokit = new Octokit({
auth: process.env.GITHUB_TOKEN,
Expand All @@ -33,8 +36,9 @@ async function addIssuesToProject(repositories: Array<string>) {

for (const issue of issues) {
console.log(
`Adding issue https://github.com/grafana/${repo}/issues/${issue.number} to the project if it's not there already.`
`Adding issue ${issue.html_url} to the project if it's not there already.`
);
added.push(issue.html_url);

const mutation = `mutation AddProjectItem($projectId: ID!, $contentId: ID!) {
addProjectV2ItemById(input: { projectId: $projectId, contentId: $contentId }) {
Expand All @@ -52,8 +56,13 @@ async function addIssuesToProject(repositories: Array<string>) {
}
} catch (error: any) {
console.error("Error adding issues to the project:", error.message);
core.setFailed(error.message);
}

return added;
}

const repositories = ["website", "writers-toolkit"];
addIssuesToProject(repositories);
const added = await addIssuesToProject(repositories);

core.setOutput("added", added.map((url) => `- ${url}`).join("\n"));
1 change: 1 addition & 0 deletions add-to-docs-project/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"@types/node": "^22.7.4"
},
"dependencies": {
"@actions/core": "^1.10.1",
"@octokit/graphql": "^8.1.1",
"@octokit/rest": "^21.0.2"
}
Expand Down
38 changes: 38 additions & 0 deletions add-to-docs-project/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,27 @@
# yarn lockfile v1


"@actions/core@^1.10.1":
version "1.10.1"
resolved "https://registry.yarnpkg.com/@actions/core/-/core-1.10.1.tgz#61108e7ac40acae95ee36da074fa5850ca4ced8a"
integrity sha512-3lBR9EDAY+iYIpTnTIXmWcNbX3T2kCkAEQGIQx4NVQ0575nk2k3GRZDTPQG+vVtS2izSLmINlxXf0uLtnrTP+g==
dependencies:
"@actions/http-client" "^2.0.1"
uuid "^8.3.2"

"@actions/http-client@^2.0.1":
version "2.2.3"
resolved "https://registry.yarnpkg.com/@actions/http-client/-/http-client-2.2.3.tgz#31fc0b25c0e665754ed39a9f19a8611fc6dab674"
integrity sha512-mx8hyJi/hjFvbPokCg4uRd4ZX78t+YyRPtnKWwIl+RzNaVuFpQHfmlGVfsKEJN8LwTCvL+DfVgAM04XaHkm6bA==
dependencies:
tunnel "^0.0.6"
undici "^5.25.4"

"@fastify/busboy@^2.0.0":
version "2.1.1"
resolved "https://registry.yarnpkg.com/@fastify/busboy/-/busboy-2.1.1.tgz#b9da6a878a371829a0502c9b6c1c143ef6663f4d"
integrity sha512-vBZP4NlzfOlerQTnba4aqZoMhE/a9HY7HRqoOPaETQcSQuWEIyZMHGfVu6w9wGtGK5fED5qRs2DteVCjOH60sA==

"@octokit/auth-token@^5.0.0":
version "5.1.1"
resolved "https://registry.yarnpkg.com/@octokit/auth-token/-/auth-token-5.1.1.tgz#3bbfe905111332a17f72d80bd0b51a3e2fa2cf07"
Expand Down Expand Up @@ -107,12 +128,29 @@ before-after-hook@^3.0.2:
resolved "https://registry.yarnpkg.com/before-after-hook/-/before-after-hook-3.0.2.tgz#d5665a5fa8b62294a5aa0a499f933f4a1016195d"
integrity sha512-Nik3Sc0ncrMK4UUdXQmAnRtzmNQTAAXmXIopizwZ1W1t8QmfJj+zL4OA2I7XPTPW5z5TDqv4hRo/JzouDJnX3A==

tunnel@^0.0.6:
version "0.0.6"
resolved "https://registry.yarnpkg.com/tunnel/-/tunnel-0.0.6.tgz#72f1314b34a5b192db012324df2cc587ca47f92c"
integrity sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg==

undici-types@~6.19.2:
version "6.19.8"
resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-6.19.8.tgz#35111c9d1437ab83a7cdc0abae2f26d88eda0a02"
integrity sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==

undici@^5.25.4:
version "5.28.4"
resolved "https://registry.yarnpkg.com/undici/-/undici-5.28.4.tgz#6b280408edb6a1a604a9b20340f45b422e373068"
integrity sha512-72RFADWFqKmUb2hmmvNODKL3p9hcB6Gt2DOQMis1SEBaV6a4MH8soBvzg+95CYhCKPFedut2JY9bMfrDl9D23g==
dependencies:
"@fastify/busboy" "^2.0.0"

universal-user-agent@^7.0.0, universal-user-agent@^7.0.2:
version "7.0.2"
resolved "https://registry.yarnpkg.com/universal-user-agent/-/universal-user-agent-7.0.2.tgz#52e7d0e9b3dc4df06cc33cb2b9fd79041a54827e"
integrity sha512-0JCqzSKnStlRRQfCdowvqy3cy0Dvtlb8xecj/H8JFZuCze4rwjPZQOgvFvn0Ws/usCHQFGpyr+pB9adaGwXn4Q==

uuid@^8.3.2:
version "8.3.2"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2"
integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==

0 comments on commit 47666f4

Please sign in to comment.