Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
Oryx/scripts/oncallAutoAssignIssue.sh at main · microsoft/Oryx · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
See all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
microsoft
Oryx
Repository navigation
Code
Issues
90
(90)
Pull requests
121
(121)
Actions
Projects
Wiki
Security and quality
Insights
More
items
Files
Expand file tree
main
Breadcrumbs
Oryx
/
scripts
/
oncallAutoAssignIssue.sh
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
105 lines (97 loc) · 3.13 KB
main
Breadcrumbs
Oryx
/
scripts
/
oncallAutoAssignIssue.sh
Copy path
Top
File metadata and controls
Code
Blame
105 lines (97 loc) · 3.13 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#!
/bin/bash
autoIssue
() {
assigneeName=
$1
token=
$2
issueNum=
$3
#
Check if the user can be assigned
echo
"
Attempting to assign user
$assigneeName
to issue
$issueNum
"
checkAccess=
$(
curl --silent --output /dev/null --write-out
"
%{http_code}
"
-L -H
"
Accept: application/vnd.github+json
"
-H
"
Authorization: Bearer
$token
"
-H
"
X-GitHub-Api-Version: 2022-11-28
"
https://api.github.com/repos/microsoft/Oryx/assignees/
$assigneeName
)
if
[[
"
$checkAccess
"
=~
^2 ]]
;
then
res=
$(
curl --silent --output /dev/null --write-out
"
%{http_code}
"
-X POST
"
https://api.github.com/repos/microsoft/Oryx/issues/
$issueNum
/assignees
"
-H
"
Accept: application/vnd.github+json
"
-H
"
Authorization: Bearer
$token
"
-d
"
{
\"
assignees
\"
: [
"
\"
$assigneeName
\"
"
]}
"
)
#
Check for curl response status
if
[[
"
$res
"
=~
^2 ]]
;
then
exit
0
else
echo
"
Error: Failed to assign isssue
$issueNum
. Check token and issue status.
"
exit
1
fi
else
echo
"
Error: Engineer Access denied.
"
return
1
fi
}
tryAssignIssueToCustomOncall
() {
today=
$1
token=
$2
issue=
$3
input=
"
$CUSTOM_ONCALL_ROTATION
"
#
Github parses new line as "\n\r". We're removing the "\n" and changing "\r" to ";" in order to parse entries
#
Removing "\n"
input=
"
${input
//
$'
\n
'
/
'
'
}
"
#
Replacing "\r" with ";"
input=
"
${input
//
$'
\r
'
/
'
;
'
}
"
if
[
-z
"
$input
"
]
;
then
return
1
fi
#
Custom oncall rotation defined in repo variable. Using format:
#
{github-username},{start-date},{end-date}
#
Divide each entry by ";"
IFS=
'
;
'
read
-ra arr
<<<
"
$input
"
for
i
in
"
${arr[@]}
"
do
#
Divide each field by ","
IFS=
'
,
'
read
-ra entry
<<<
"
$i
"
name=
$(
echo
${entry[0]}
)
startDate=
$(
echo
${entry[1]}
)
endDate=
$(
echo
${entry[2]}
)
startDate=
$(
date -d
$startDate
+%s
)
endDate=
$(
date -d
$endDate
+%s
)
if
[
"
$today
"
-ge
"
$startDate
"
]
&&
[
"
$today
"
-le
"
$endDate
"
]
;
then
echo
"
Custom oncall found for
$name
"
autoIssue
$name
$token
$issue
fi
done
}
#
https://medium.com/@Drew_Stokes/bash-argument-parsing-54f3b81a6a8f
PARAMS=
"
"
while
((
"
$#
"
))
;
do
case
"
$1
"
in
--token)
#
Github token flag
authToken=
$2
shift
2
;;
--issue)
#
Issue number flag
issueNum=
$2
shift
2
;;
--)
shift
break
;;
*
)
PARAMS=
"
$PARAMS
$1
"
shift
;;
esac
done
eval
set
--
"
$PARAMS
"
today=
$(
date +%s
)
#
Oncall rotation is defined in repo variable. Using format:
#
{github-username-1},{github-username-2},...
#
Parsing oncall engineer lists into array and seperating them by ','
IFS=
'
,
'
read
-ra parsedOncalls
<<<
"
$ONCALL_LIST
"
oncallArrLen=
${
#
parsedOncalls[@]}
#
anchor Date is Nov 7 2023 10:00 PST
anchorDate=1699380000
d=
$((
(today
-
anchorDate)
/
60
/
60
/
24
/
7
))
pos=
`
echo
"
$d
%
$oncallArrLen
"
|
bc
`
currentOncall=
`
echo
${parsedOncalls[$pos]}
`
#
Check if custom rotation env var is present or not
if
[
-n
"
$CUSTOM_ONCALL_ROTATION
"
]
;
then
#
If yes, try assign it to custom oncall engineer
#
Function exit 0 when successfully assigned it to custom oncall engineer
tryAssignIssueToCustomOncall
$today
$authToken
$issueNum
fi
#
If failed, then assign to current oncall.
autoIssue
$currentOncall
$authToken
$issueNum
exit
1
You can’t perform that action at this time.