-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchangelog.js
123 lines (105 loc) · 3.31 KB
/
changelog.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
const axios = require("axios")
require('dotenv').config()
const fs = require("fs");
let content = ""
const tagNameArg = process.argv.slice(2)[0];
const repo = "TimePHP-Rest";
let firstCommit = true
let jsonString = fs.readFileSync('./config.json')
let config = JSON.parse(jsonString)
axios({
url: 'https://api.github.com/graphql',
method: 'post',
headers: {
'Authorization': `bearer ${process.env.GITHUB_TOKEN}`,
'Content-Type': 'application/json'
},
data: {
query: `
query {
repository(owner: "TimePHP-Org", name: "${repo}") {
release(tagName:"${tagNameArg}") {
createdAt
id
isPrerelease
tagName
url
}
}
}
`
}
}).then((result) => {
// console.table(result.data.data.repository.release.tagName);
let release = result.data.data.repository.release
axios({
url: 'https://api.github.com/graphql',
method: 'post',
headers: {
'Authorization': `bearer ${process.env.GITHUB_TOKEN}`,
'Content-Type': 'application/json'
},
data: {
query: `
query {
repository(owner: "TimePHP-Org", name: "${repo}") {
ref(qualifiedName: "${tagNameArg}") {
target {
... on Commit {
history(since: "${config.lastCommit}") {
nodes {
oid
messageHeadline
url
committedDate
}
}
}
}
}
}
}
`
}
}).then((result) => {
let date = new Date(release.createdAt).toLocaleDateString().split("-")
let feat = ""
let bug = ""
content += `## ${release.tagName}
**Release date** : ${date[0]}-${("0" + date[1]).slice(-2)}-${("0" + date[2]).slice(-2)} <br>
**Status** : ${release.isPrerelease ? "Pre-release" : "Release"} <br>
**link** : [${release.tagName}](${release.url})
`
let commits = result.data.data.repository.ref.target.history.nodes
commits.forEach(commit => {
if(firstCommit){
config["lastCommit"] = commit.committedDate
let data = JSON.stringify(config);
fs.writeFileSync('./config.json', data);
}
firstCommit = false
if(commit.messageHeadline.startsWith("[add]") || commit.messageHeadline.startsWith("[feat]")){
feat += `
- ${commit.messageHeadline.replace("[add]", "").replace("[feat]", "")} ([${commit.oid.substring(0, 7)}](${commit.url}))`
} else if(commit.messageHeadline.startsWith("[fix]") || commit.messageHeadline.startsWith("[bug]")){
bug += `
- ${commit.messageHeadline.replace("[fix]", "").replace("[bug]", "")} ([${commit.oid.substring(0, 7)}](${commit.url}))`
}
})
if(feat !== ""){
content += `
### Features
${feat}
`
}
if(bug !== ""){
content += `
### Bug fixes
${bug}
<br>
`
}
let data = fs.writeFileSync("./changelogTmp.md", content, "utf-8")
console.log(`Changelog temp file updated for release : ${tagNameArg} !`)
})
})