Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/bin/check-upstream-bug-tracker
blob: a8d3476c4d558a76c4967c6b0effd78a3c6de254 (plain)
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/bin/sh

# shellcheck source=../lib/load-configuration
. "${0%/*}/../lib/load-configuration"

# shellcheck disable=SC2016
usage() {
  >&2 echo ''
  >&2 echo 'check-upstrea-bug-tracker: check archlinux'"'"' bug tracker'
  >&2 echo 'for open bugs on packages that fail to build'
  >&2 echo ''
  >&2 echo 'possible options:'
  >&2 echo '  -h|--help:    Show this help and exit.'
  >&2 echo '  -f|--failure $identifier:'
  >&2 echo '    only check packages which fail due to $identifier'
  [ -z "$1" ] && exit 1 || exit "$1"
}

eval set -- "$(
  getopt -o f:h \
    --long failure: \
    --long help \
    -n "$(basename "$0")" -- "$@" || \
  echo usage
)"
identifier=''

while true
do
  case "$1" in
    -f|--failure)
      shift
      if [ -n "${identifier}" ]; then
        >&2 echo 'Option -f only allowed once.'
        usage
      fi
      identifier="$1"
    ;;
    -h|--help)
      usage 0
    ;;
    --)
      shift
      break
    ;;
    *)
      >&2 echo 'Whoops, forgot to implement option "'"$1"'" internally.'
      exit 42
    ;;
  esac
  shift
done

if [ $# -ne 0 ]; then
  >&2 echo 'Too many arguments.'
  usage
fi

tmp_dir=$(mktemp -d 'tmp.check-upstream-bug-tracker.XXXXXXXXXX' --tmpdir)
trap 'rm -rf --one-file-system "${tmp_dir}"' EXIT

>&2 printf 'receiving upstream bugs of broken packages '

# shellcheck disable=SC2016
{
  printf 'SELECT DISTINCT'
  printf '`package_sources`.`%s`,' \
    'pkgbase' \
    'git_revision' \
    'mod_git_revision'
  printf '`upstream_repositories`.`name`'
  printf ' FROM `package_sources`'
  mysql_join_package_sources_upstream_repositories
  mysql_join_package_sources_build_assignments
  if [ -n "${identifier}" ]; then
    mysql_join_build_assignments_failed_builds
    mysql_join_failed_builds_fail_reasons
    printf ' AND `fail_reasons`.`name`=from_base64("%s")' \
      "$(
        printf '%s' "${identifier}" | \
          base64 -w0
      )"
  fi
  mysql_join_build_assignments_binary_packages
  mysql_join_binary_packages_binary_packages_in_repositories
  printf ' WHERE `binary_packages_in_repositories`.`repository`=%s' \
    "${repository_ids__any_build_list}"
  printf ' AND `build_assignments`.`is_broken`'
  printf ' AND `build_assignments`.`is_blocked` IS NULL;\n'
} | \
  mysql_run_query 'unimportant' | \
  while read -r pkgbase git_revision mod_git_revision repository; do
    >&2 printf '.'
    curl -Ssg 'https://bugs.archlinux.org/index.php?string=['"${pkgbase}"']&project=5&status[]=open' | \
      sed -n '
        s@^.*<td class='"'"'task_id'"'"'><a href="https://bugs\.archlinux\.org/task/\([0-9]\+\)?.*<td class='"'"'task_summary'"'"'><a href=[^>]\+>\(.*\)</a></td>.*$@\1\t\2@
        T
        s/^/'"${pkgbase}.${git_revision}.${mod_git_revision}.${repository}"'\t/
        p
      '
  done > \
  "${tmp_dir}/broken-packages"

>&2 printf ' done\n'

while [ -s "${tmp_dir}/broken-packages" ]; do
  identifier=$(
    head -n1 "${tmp_dir}/broken-packages" | \
      cut -f1
  )
  fs_ids=''
  OIFS="${IFS}"
  lines=$(
    grep "^$(str_to_regex "${identifier}")\\s" "${tmp_dir}/broken-packages" | \
      cut -f2,3 | \
      tr '\t\n' '\n\t'
  )
  IFS=$(printf '\t')
  # shellcheck disable=SC2013
  for line in ${lines}; do
    IFS="${OIFS}"
    printf '> '
    printf '%s' "${line}" | \
      tr '\t\n' '\n\t' | \
      cut -f2
    printf 'Should we wait (empty = "yes")? '
    read -r w
    if [ -z "${w}" ]; then
      fs_ids="${fs_ids},FS#$(
        printf '%s\n' "${line}" | \
          tr '\t\n' '\n\t' | \
          cut -f1
      )"
    fi
  done
  IFS="${OIFS}"
  if [ -n "${fs_ids}" ]; then
    printf '%s.any wait for %s\n' \
      "${identifier}" \
      "${fs_ids#,}" >> \
      "${tmp_dir}/block-list"
  fi
  sed -i '/^'"$(str_to_regex "${identifier}")"'\s/d' "${tmp_dir}/broken-packages"
done

if [ -s "${tmp_dir}/block-list" ]; then
  "${base_dir}/bin/modify-package-state" -w -b "${tmp_dir}/block-list"
fi