-
Notifications
You must be signed in to change notification settings - Fork 731
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d683a25
commit 4f9b165
Showing
1 changed file
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
const axios = require("axios"); | ||
const lodash = require("lodash"); | ||
const fs = require("fs"); | ||
|
||
|
||
const accessTokens = "xxx"; | ||
const main = async () => { | ||
const getIssues = async (pageNum, since) => { | ||
console.log("trying get issue page", pageNum); | ||
const res = await axios.get(`https://api.github.com/repos/DouyinFE/semi-design/issues`, { | ||
params: { | ||
since, | ||
page: pageNum, | ||
state: "all", | ||
}, | ||
headers: { | ||
Authorization: `Bearer ${accessTokens}` | ||
} | ||
}); | ||
if (res.status !== 200 || !res.data || res.data.length===0) { | ||
return null; | ||
} | ||
return res.data; | ||
}; | ||
|
||
let list = []; | ||
|
||
const since = "2023-01-01"; | ||
let currentPage = 1; | ||
while (true) { | ||
const data = await getIssues(currentPage, since); | ||
if (data) { | ||
list = [...list, ...data]; | ||
} else { | ||
break; | ||
} | ||
currentPage++; | ||
|
||
} | ||
|
||
console.log(`Find ${list.length} issues since ${since}`); | ||
|
||
const result = {}; | ||
|
||
const whichQ = (dateRaw) => { | ||
const date = new Date(dateRaw); | ||
const month = date.getMonth() + 1; | ||
return Math.ceil(month / 3); | ||
|
||
}; | ||
|
||
list.forEach(issue => { | ||
const createdAt = issue['created_at']; | ||
const closedAt = issue['closed_at']; | ||
(()=>{ | ||
const tmp = lodash.get(result, [`q${whichQ(createdAt)}`, "created"], []); | ||
tmp.push(issue); | ||
lodash.set(result, [`q${whichQ(createdAt)}`, "created"], tmp); | ||
})(); | ||
|
||
if (closedAt!==null) { | ||
(()=>{ | ||
const tmp = lodash.get(result, [`q${whichQ(closedAt)}`, "closed"], []); | ||
tmp.push(issue); | ||
lodash.set(result, [`q${whichQ(closedAt)}`, "closed"], tmp); | ||
})(); | ||
} | ||
}); | ||
|
||
|
||
fs.writeFileSync("./output.json", JSON.stringify(list, null, " ")); | ||
Object.entries(result).forEach(([q, data])=>{ | ||
console.log(`${q}: created ${data.created.length} closed ${data.closed.length}`); | ||
}); | ||
}; | ||
|
||
|
||
main(); |