-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathissue.sh
More file actions
executable file
·119 lines (103 loc) · 4.54 KB
/
issue.sh
File metadata and controls
executable file
·119 lines (103 loc) · 4.54 KB
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
#!/bin/bash -e
dir=$(dirname $0)
while getopts o:u:p:t:i:d:C: option
do
case "${option}"
in
o) projectId=${OPTARG};;
t) token=${OPTARG};;
u) user=${OPTARG};;
p) pass=${OPTARG};;
i) issueId=${OPTARG};;
d) numDays=${OPTARG};;
C) consolidate=${OPTARG};;
esac
done
if [[ "$consolidate" == "" ]];then
consolidate="false"
fi
if [[ "$token" == "" ]];then
token=$($dir/login.sh $user $pass)
fi
if [ "$token" == "" -o "$token" == "null" ];then
echo "INVALID TOKEN - check usage"
exit 1
fi
if [[ "$projectId" == "" ]];then
projects=$($dir/projects.sh -t $token | jq '.')
text=$(echo $projects | jq -r '. | sort_by(.name) | to_entries[] | " \(.key)) (\(.value.platform)) \(.value.name) - \(.value.identifier)"')
text="$text"
echo -e "Choose project:\n\n$text\n\nProject number, followed by [ENTER]:"
read projectNumber
projectId=$(echo $projects | jq --argjson num "$projectNumber" -r '. | sort_by(.name)[$num].externalId')
fi
if [ "$projectId" == "" -o "$projectId" == "null" ];then
echo "INVALID PROJECT ID - check usage"
exit 1
fi
if [[ "$issueId" == "" ]];then
issues=$($dir/issues.sh -t $token -o $projectId -v Z | jq '.')
text=$(echo $issues | jq -r '. | sort_by(-.createdAt) | to_entries[] | " \(.key)) (\(.value.state)/\(.value.type)) [ \(.value.occurrenceCount) ] \(.value.title) - \(.value.subtitle)"')
text="$text"
echo -e "Choose issue:\n\n$text\n\nIssue number, followed by [ENTER]:"
read issueNumber
issueId=$(echo $issues | jq --argjson num "$issueNumber" -r '. | sort_by(-.createdAt)[$num].externalId')
fi
versions=$($dir/versions.sh -t $token -o $projectId)
startDate=$(($(date -u -d "00:00:00 $numDays days ago" +%s)*1000))
endDate=$(($(date -u -d "23:59:59" +%s)*1000))
fEndDate=$(date -d @$(($endDate/1000)) +"%Y%m%d")
formattedDates="_$fEndDate"
started=false
while [[ $result != "" || "$started" == "false" ]]; do
started=true
if [[ "$result" == "" ]];then
params="externalId:\\\"latest\\\",issueId:\\\"$issueId\\\""
variables=" \"externalId_0\":\"$projectId\" "
methodParams=" \$externalId_0:String! "
else
params="issueId:\\\"$issueId\\\",pageTime:\$pageTime_1, pageDirection:\$pageDirection_2"
variables="\"externalId_0\":\"$projectId\", \"pageTime_1\":$createdAt,\"pageDirection_2\":\"previous\""
methodParams=" \$externalId_0:String! , \$pageTime_1:UnixMsTimestamp! , \$pageDirection_2:CrashSessionPaginationDirection! "
fi
result=$(curl -s 'https://api-dash.fabric.io/graphql?relayDebugName=SingleSession' \
-H "Authorization: Bearer $token" -H 'Content-Type: application/json' \
--data-binary "{\"query\":\"query SingleSession($methodParams) \
{project(externalId:\$externalId_0) {crashlytics \
{_session1SEzhR:session($params) \
{externalId,createdAt,buildVersionId, \
stacktraces \
{exceptions {caption {title,subtitle}}}}}}}\", \
\"variables\":{$variables}}" --compressed)
result=$(echo "$result" | jq '.data.project.crashlytics[] | select(has("externalId"))')
result=$(echo $result | jq '. | .stacktraces = ([.stacktraces.exceptions[] | .caption])')
createdAt=$(echo "$result" | jq '.createdAt')
if [[ "$createdAt" == "" ]];then
break
fi
if [[ $startDate -gt $createdAt ]];then
break
fi
if [[ "$jsonFile" == "" ]];then
exceptionName=$(echo $result | jq -r '.stacktraces[0].title')
exceptionName=$(echo $exceptionName | awk '{print $NF;}' )
exceptionName=${exceptionName//\./\ }
exceptionName=$(echo $exceptionName | awk '{print $NF;}' )
mkdir -p $dir/gen
jsonFile="$dir/gen/$exceptionName$formattedDates.json"
echo "" > $jsonFile
echo "generated report: $jsonFile"
fi
formatteddDate=$(($createdAt/1000))
formatteddDate=$(date -d @$formatteddDate +"%Y-%m-%d %H:%M:%S")
buildVersion=$(echo "$result" | jq -r '.buildVersionId')
versionName=$(echo $versions | jq --arg id $buildVersion -r '.[] | select(.externalId == $id) | .name' )
if [[ "$consolidate" == "false" ]];then
echo $result | jq --argjson tForm "{\"createdAtString\":\"$formatteddDate\",\"buildVersionName\":\"$versionName\"""}" '. += . + $tForm'
fi
echo $result | jq -c --argjson tForm "{\"createdAtString\":\"$formatteddDate\",\"buildVersionName\":\"$versionName\"""}" '. += . + $tForm' >> $jsonFile
echo -e "\n" >> $jsonFile
done
if [[ "$consolidate" != "false" ]];then
$dir/consolidate.sh -f $jsonFile
fi