【发布时间】:2022-06-22 14:37:33
【问题描述】:
我有一个脚本,它使用 jq 将一堆 github 信息导入为 .tf 文件
function get_team_repos() {
log "Importing team repositories..." "INFO"
for PAGE in $(limit_team_pagination); do
for i in $(curl --silent -s -u "$USERNAME:$GITHUB_TOKEN" "${API_URL_PREFIX}/orgs/$ORG/teams/${TEAM_ID}/repos?page=${PAGE}&per_page=100" | jq -M -r 'sort_by(.name) | .[] | .name'); do
TERRAFORM_TEAM_REPO_NAME=$(echo "${i}" | tr "." "-")
log "Team repo: $TERRAFORM_TEAM_REPO_NAME" "INFO"
TEAM_NAME=$(curl --silent -s -u "$USERNAME:$GITHUB_TOKEN" "${API_URL_PREFIX}/orgs/$ORG/teams" -H "Accept: application/vnd.github.v3+json" | jq -M -r 'sort_by(.name) | .[] | .name' | tr " " "_" | tr "/" "_")
log "Working on $TEAM_NAME" "INFO"
PERMS_PAYLOAD=$(curl --silent -s -u "$USERNAME:$GITHUB_TOKEN" "${API_URL_PREFIX}/orgs/${ORG}/teams/${TEAM_ID}/repos" -H "Accept: application/vnd.github.v3.repository+json")
ADMIN_PERMS=$(echo "$PERMS_PAYLOAD" | jq -M -r .permissions.admin)
PUSH_PERMS=$(echo "$PERMS_PAYLOAD" | jq -M -r .permissions.push)
PULL_PERMS=$(echo "$PERMS_PAYLOAD" | jq -M -r .permissions.pull)
if [[ "${ADMIN_PERMS}" == "true" ]]; then
cat >>"github-teams-${TEAM_NAME}.tf" <<EOF
提示如下错误:
jq: error (at <stdin>:4): Cannot index string with string "name"
╷
│ Error: Attribute name required
│
│ on <import-address> line 1:
│ 1: github_team_repository.-
│
│ Dot must be followed by attribute name.
╵
有人知道吗?
【问题讨论】:
-
哪个 jq 行导致了问题,你能给我们一个 jq 语句的输入样本吗?使用正确的环境执行
curl --silent -s -u "$USERNAME:$GITHUB_TOKEN" "${API_URL_PREFIX}/orgs/$ORG/teams/${TEAM_ID}/repos?page=${PAGE}&per_page=100",看看会发生什么。 -
其实这是我的错,jq 语句似乎没问题,terraform 不喜欢 '.'在资源名称中,所以我不得不添加这个
TERRAFORM_TEAM_REPO_NAME=$(echo "${i}" | tr "." "-")问题中的 curl 会提示以下内容:{ "message": "Not Found", "documentation_url": "https://docs.github.com/rest" } -
看来api调用已经过时了,我的错,在我继续之前我必须看看新的api是什么样子的,谢谢
-
我认为可能是这样的。
-
没有 jq 位的 curl 的输出是什么?
标签: bash devops jq github-api