Skip to content

Commit

Permalink
removed octokit
Browse files Browse the repository at this point in the history
  • Loading branch information
muratgozel committed Aug 19, 2024
1 parent fea0e92 commit 5e2f31b
Show file tree
Hide file tree
Showing 6 changed files with 1,202 additions and 2,590 deletions.
41 changes: 25 additions & 16 deletions lib/domain/Github.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import {Octokit} from "octokit";
import got from "got";

class Github {
token=null
userAgent=null
octokit=null

constructor({token, userAgent}) {
this.token = token
Expand All @@ -12,23 +11,33 @@ class Github {
}

init() {
this.octokit = new Octokit({
auth: this.token,
userAgent: this.userAgent,
timeZone: this.userTimeZone
})
}

async createRelease(owner, repo, tag, body) {
const response = await this.octokit.request('POST /repos/{owner}/{repo}/releases', {
owner: owner,
repo: repo,
tag_name: tag,
body: body
})

if (response.status != 201) {
return new Error(`Github release failed. The response was ${response.data}`)
try {
const response = await got({
method: 'POST',
url: `https://api.github.com/repos/${owner}/${repo}/releases`,
headers: {
'Authorization': `Bearer ${this.token}`,
'Accept': 'application/vnd.github+json',
'X-GitHub-Api-Version': '2022-11-28'
},
json: {
tag_name: tag,
body: body
}
})

try {
const body = JSON.parse(response.rawBody.toString())
}
catch (err2) {
return new Error(`Github release failed. Couldn't parse response body.`, {cause: err2})
}
}
catch (err) {
return new Error(`Github release failed: ${e.message}`, {cause: err})
}

return true
Expand Down
3 changes: 1 addition & 2 deletions lib/domain/Gitlab.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ class Gitlab {
url: `https://gitlab.com/api/v4/projects/${urlEncodedPath}/releases`,
headers: {
'PRIVATE-TOKEN': this.token,
'Content-Type': 'application/json',
'User-Agent': this.userAgent
'Content-Type': 'application/json'
},
json: {
tag_name: tag,
Expand Down
Loading

0 comments on commit 5e2f31b

Please sign in to comment.