Skip to content

Update offersku.json #125

Update offersku.json

Update offersku.json #125

Workflow file for this run

name: build
on:
push:
branches: [ main ]
paths:
- 'offersku.json'
jobs:
createIssue:
env:
GH_TOKEN: ${{secrets.ISSUE_TOKEN}}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
name: Check out code
- name: handle-list
run: |
# 删除issue模板文件前的元信息
cat .github/ISSUE_TEMPLATE/create_offersku.md > template.md
deleteRow=$(grep -n "\-\-\-" template.md | cut -d ":" -f 1 | sed -n '2p')
for ((index=0;index<$deleteRow;index++));do
sed -i '1d' template.md
done
# 创建milestone
milestone=$(cat offersku.json | jq '.milestone')
allMilestones=$(curl \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{github.token}}"\
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${{github.repository_owner}}/manufacture/milestones | jq '.[] | .title')
createFlag="true"
for item in $allMilestones;do
if [[ $item == $milestone ]];then
createFlag="false"
break
fi
done
if [[ $createFlag == "true" ]];then
curl \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{github.token}}"\
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${{github.repository_owner}}/manufacture/milestones \
-d '{"title":'$milestone',"state":"open"}'
fi
# query the ID of the project
PROJECT_NUMBER=11
ORGANIZATION="Websoft9"
gh api graphql -f query='
query($org: String!, $number: Int!) {
organization(login: $org){
projectV2(number: $number) {
id
fields(first:20) {
nodes {
... on ProjectV2Field {
id
name
}
... on ProjectV2SingleSelectField {
id
name
options {
id
name
}
}
}
}
}
}
}' -f org=$ORGANIZATION -F number=$PROJECT_NUMBER > project_data.json
echo 'PROJECT_ID='$(jq '.data.organization.projectV2.id' project_data.json) >> $GITHUB_ENV
echo 'STATUS_FIELD_ID='$(jq '.data.organization.projectV2.fields.nodes[] | select(.name== "Status") | .id' project_data.json) >> $GITHUB_ENV
echo 'TODO_OPTION_ID='$(jq '.data.organization.projectV2.fields.nodes[] | select(.name== "Status") | .options[] | select(.name=="制造") |.id' project_data.json) >> $GITHUB_ENV
list=$(jq "[.task[] | {appname:.appname,distribution:.distribution[],platform:.platform[],os:.os[],assignees:.assignees,updateornew:.updateornew}]" offersku.json)
length=$(echo $list | jq '.|length')
declare -A map
map=(["金晟"]="jinsheng200303" ["崔志坚"]="czj69233" ["欧玉成"]="cbnb233")
# 创建issue
for ((index=0;index<$length;index++));do
appname=$(echo $list | jq -r ".[$index].appname")
distribution=$(echo $list | jq -r ".[$index].distribution")
platform=$(echo $list | jq -r ".[$index].platform")
os=$(echo $list | jq -r ".[$index].os")
assignee=${map[$(echo $list | jq -r ".[$index].assignees")]}
updateornew=$(echo $list | jq -r ".[$index].updateornew")
stone=$(echo $milestone | sed 's/\"//g')
applabel="App"
# 根据appname的值来决定applabel的值
if [[ $appname == "websoft9" ]]; then
issue_number=$(gh issue create --assignee $assignee --title "$updateornew SKU $appname on $platform on $os" --body-file template.md --label "$distribution" --milestone "$stone" --project "商品生产发布" | awk -F "/" '{print $NF}')
else
issue_number=$(gh issue create --assignee $assignee --title "$updateornew SKU $appname on $platform on $os" --body-file template.md --label "$distribution,$applabel" --milestone "$stone" --project "商品生产发布" | awk -F "/" '{print $NF}')
fi
echo $issue_number
# 关联Status
gh api graphql -f query='
mutation (
$project: ID!
$item: ID!
$status_field: ID!
$status_value: String!
) {
set_status: updateProjectV2ItemFieldValue(input: {
projectId: $project
itemId: $item
fieldId: $status_field
value: {
singleSelectOptionId: $status_value
}
}) {
projectV2Item {
id
}
}
}' -f project=$PROJECT_ID -f item=$issue_number -f status_field=$STATUS_FIELD_ID -f status_value=${{ env.TODO_OPTION_ID }} -f
done