From 8b23228b55013bb07e5d03e024da404cfd4ff2c2 Mon Sep 17 00:00:00 2001 From: jinhojang6 Date: Tue, 31 Oct 2023 20:56:30 +0900 Subject: [PATCH] set up Jenkinsfile and nodejs script to fetch open issues --- Jenkinsfile | 33 ++++++++++++++ script.js | 126 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 159 insertions(+) create mode 100644 Jenkinsfile create mode 100644 script.js diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..2e53626 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,33 @@ +pipeline { + agent { label 'linux' } + + options { + disableConcurrentBuilds() + /* manage how many builds we keep */ + buildDiscarder(logRotator( + numToKeepStr: '20', + daysToKeepStr: '30', + )) + } + + environment { + GIT_COMMITTER_NAME = 'status-im-auto' + GIT_COMMITTER_EMAIL = 'auto@status.im' + } + + stages { + stage('Build') { + steps { + sh 'mdbook build' + } + } + + stage('Publish') { + steps { + sshagent(credentials: ['status-im-auto-ssh']) { + sh "ghp-import -p book" + } + } + } + } +} \ No newline at end of file diff --git a/script.js b/script.js new file mode 100644 index 0000000..506272b --- /dev/null +++ b/script.js @@ -0,0 +1,126 @@ +const https = require("https"); + +if (process.argv.length < 4) { + console.error("Usage: node script.js [owner] [repo]"); + process.exit(1); +} + +const owner = process.argv[2]; +const repo = process.argv[3]; + +const query = ` +{ + repository(owner: "${owner}", name: "${repo}") { + issues(first: 100, states: OPEN) { + nodes { + id + title + url + author { + login + avatarUrl + } + labels(first: 10) { + nodes { + name + } + } + commentCount: comments { + totalCount + } + commentsDetailed: comments(first: 10) { + nodes { + id + author { + login + } + body + createdAt + } + } + assignees(first: 10) { + nodes { + login + avatarUrl + } + } + milestone { + title + } + createdAt + updatedAt + projectCards(first: 10) { + nodes { + project { + name + url + } + } + } + } + } + } +} +`; + +const options = { + hostname: "api.github.com", + path: "/graphql", + method: "POST", + headers: { + "User-Agent": "NodeJS-Script", + Authorization: "bearer YOUR_GITHUB_TOKEN", // Note: Using bearer for GraphQL + "Content-Type": "application/json", + }, +}; + +const req = https.request(options, (res) => { + let data = ""; + + res.on("data", (chunk) => { + data += chunk; + }); + + res.on("end", () => { + try { + const response = JSON.parse(data); + console.log("Response:", response); + const rawIssues = response.data?.repository?.issues.nodes; + + const extractedIssues = rawIssues.map((issue) => ({ + id: issue.id, + title: issue.title, + url: issue.url, + user: { + login: issue.author.login, + avatarUrl: issue.author.avatarUrl, + }, + labels: issue.labels.nodes.map((label) => label.name), + commentCount: issue.commentCount.totalCount, + comments: issue.commentsDetailed.nodes.map(comment => ({ + id: comment.id, + author: comment.author.login, + body: comment.body, + createdAt: comment.createdAt + })), + assignees: issue.assignees.nodes, + milestone: issue.milestone ? issue.milestone.title : null, + created_at: issue.createdAt, + updated_at: issue.updatedAt, + projects: issue.projectCards.nodes.map((card) => card.project), + })); + + console.log(JSON.stringify(extractedIssues, null, 2)); + return extractedIssues + } catch (error) { + console.error("Failed to parse response:", error); + } + }); +}); + +req.on("error", (error) => { + console.error(`Got an error: ${error.message}`); +}); + +req.write(JSON.stringify({ query })); +req.end(); \ No newline at end of file