Skip to content

Commit 6a8e21d

Browse files
authored
adding error message when permission token of github is not sufficient (#21)
* added error handling when token doesn't have much scope * added optional chaining operator for url
1 parent b57ab5d commit 6a8e21d

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

fastlane.js

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
const githubUsername = process.env.HUBOT_GITHUB_USERNAME
33
const githubToken = process.env.HUBOT_GITHUB_TOKEN
44
const organisation = "owncloud"
5+
const projectName = "QA/CI/TestAutomation"
56
const projectNumber = 386
67
const fastLaneColumnName = "Fastlane"
78
const itemsPerRequest = 50 // number of items (issues/PRs) to fetch from the project board
@@ -21,8 +22,8 @@ const fastlaneCards = []
2122

2223
const filterFastlaneCards = (cards) => {
2324
cards.forEach((card) => {
24-
const url = card.content.url
25-
const columnName = card.fieldValueByName.name
25+
const url = card?.content?.url
26+
const columnName = card?.fieldValueByName?.name
2627

2728
if (url && columnName && columnName === fastLaneColumnName) {
2829
fastlaneCards.push(url)
@@ -36,6 +37,7 @@ const generateQuery = (itemArg) => {
3637
return `query {
3738
organization(login: "${organisation}"){
3839
projectV2(number: ${projectNumber}){
40+
title
3941
items(${itemArg}) {
4042
nodes{
4143
content{
@@ -78,11 +80,37 @@ const reportFastlaneCards = (robot) =>
7880
return
7981
}
8082
const parsedBody = JSON.parse(body)
83+
84+
if (Object.hasOwn(parsedBody, "errors")) {
85+
const errorTypes = parsedBody.errors.map((error) => error.type)
86+
if (errorTypes.every((type) => type === "INSUFFICIENT_SCOPES")) {
87+
robot.emit(
88+
"error",
89+
`could not find project '${projectName}' . Do you have the right permissions?`
90+
)
91+
return
92+
}
93+
94+
if (errorTypes.every((type) => type === "NOT_FOUND")) {
95+
console.log("I am error")
96+
robot.emit(
97+
"error",
98+
`could not find project'${projectName}' with number ${projectNumber}`
99+
)
100+
return
101+
}
102+
}
103+
81104
if (!parsedBody.data) {
82105
robot.emit("error", `Response doesn't have data: '${err}'`)
83106
return
84107
}
85108

109+
if (parsedBody.data.organization.projectV2.title !== projectName) {
110+
robot.emit("error", `Project title from response doesn't match`)
111+
return
112+
}
113+
86114
const items = parsedBody.data.organization.projectV2.items
87115
endCursor = items.pageInfo.endCursor
88116

0 commit comments

Comments
 (0)