AI agent skill that researches any topic across Reddit, X, YouTube, HN, Polymarket, and the web - then synthesizes a grounded summary
Python ai-promptsai-skillblueskyclaudeclaude-codeclawhubdeep-researchhackernewsinstagramopenclawpolymarketrecencyredditresearchsocial-mediatiktoktrendstwitterweb-searchyoutube
fix(github): query is:issue and is:pull-request when authenticated + partition honesty (#994)
Matt Van Horn55885bcacc41
diff --git a/changelog.d/967.fixed.md b/changelog.d/967.fixed.mdnew file mode 100644index 00000000..7cc70247--- /dev/null+++ b/changelog.d/967.fixed.md@@ -0,0 +1 @@+The GitHub source no longer returns zero results once a credential is available. GitHub rejects authenticated `/search/issues` requests that carry neither `is:issue` nor `is:pull-request` with HTTP 422, while anonymous requests are still accepted without one — so the source worked until a user ran `gh auth login` or set `GITHUB_TOKEN`, then failed silently while `doctor` still reported it healthy. Authenticated searches now run both qualifier-scoped queries and merge them, deduped by item id and re-sorted by reaction count, which keeps issues and pull requests in the same result set; appending a single qualifier would have dropped roughly 87% of matches on a typical topic. The unauthenticated path is unchanged. When one partition fails but the other returns items, the surviving items are now kept and the source is reported as partial rather than silently claiming success — full-failure (both partitions return nothing) is still a clear failure.diff --git a/skills/last30days/scripts/lib/github.py b/skills/last30days/scripts/lib/github.pyindex 30e4faa0..944c0501 100644--- a/skills/last30days/scripts/lib/github.py+++ b/skills/last30days/scripts/lib/github.py@@ -253,21 +253,66 @@ def search_github(_log(f"Searching for '{core}' (raw: '{topic}', since {from_date}, count={count})")# Build search query with date filter- q = f"{core} created:>{from_date}"- params = {- "q": q,- "sort": "reactions",- "order": "desc",- "per_page": str(min(count, 100)),- }- url = f"{SEARCH_URL}?{urllib.parse.urlencode(params)}"+ base_q = f"{core} created:>{from_date}"++ def _search(qualifier: Optional[str]) -> Optional[Dict[str, Any]]:+ q = f"{base_q} {qualifier}" if qualifier else base_q+ params = {+ "q": q,+ "sort": "reactions",+ "order": "desc",+ "per_page": str(min(count, 100)),+ }+ url = f"{SEARCH_URL}?{urllib.parse.urlencode(params)}"+ return _fetch_json(url, token=resolved_token, timeout=30,+ failure_out=fetch_failures)fetch_failures: List[str] = []- data = _fetch_json(url, token=resolved_token, timeout=30, failure_out=fetch_failures)+ partition_failure: Optional[str] = None+ if authed:+ # GitHub rejects AUTHENTICATED /search/issues queries that carry+ # neither `is:issue` nor `is:pull-request` (HTTP 422). Anonymous+ # queries are still grandfathered, which is why this only bites once+ # a token is present -- including via the `gh auth token` fallback.+ #+ # Appending a single qualifier would silently halve the corpus: for+ # "rust async created:>2026-08-02" GitHub reports 1,072 issues and+ # 7,044 pull requests against 8,115 combined, so `is:issue` alone+ # drops ~87% of matches. Query both and merge instead, which keeps+ # coverage AND the authenticated rate limit.+ merged: List[Dict[str, Any]] = []+ seen_ids = set()+ failed_qualifiers: List[str] = []+ for qualifier in ("is:issue", "is:pull-request"):+ part = _search(qualifier)+ if part is None:+ failed_qualifiers.append(qualifier)+ continue+ for item in part.get("items", []):+ item_id = item.get("id")+ if item_id in seen_ids:+ continue+ seen_ids.add(item_id)+ merged.append(item)+ # Both sub-queries are reaction-sorted; the merge is not, so re-sort+ # before truncating or the second query's tail would outrank the+ # first query's head.+ merged.sort(key=lambda i: (i.get("reactions") or {}).get("total_count", 0),+ reverse=True)+ data = {"items": merged[:count]} if merged else None+ if failed_qualifiers:+ partition_failure = (+ f"GitHub partition(s) failed: {', '.join(failed_qualifiers)}"+ + (f" ({fetch_failures[-1]})" if fetch_failures else "")+ )+ else:+ data = _search(None)if not data:envelope = {"items": [], "context": {"core": core, "from_date": from_date,"to_date": to_date, "count": count}}- if authed and fetch_failures:+ if authed and partition_failure:+ envelope["error"] = partition_failure+ elif authed and fetch_failures:# Authenticated transport failures must not be laundered into a# clean no-results outcome (issue #384).envelope["error"] = f"GitHub API request failed: {fetch_failures[-1]}"@@ -284,7 +329,7 @@ def search_github(raw_items = data.get("items", [])_log(f"Found {len(raw_items)} issues/PRs")- return {+ envelope: Dict[str, Any] = {"items": raw_items,"context": {"core": core,@@ -293,6 +338,9 @@ def search_github("count": count,},}+ if partition_failure:+ envelope["error"] = partition_failure+ return envelopedef parse_github_response(response: Dict[str, Any]) -> List[Dict[str, Any]]:diff --git a/tests/test_github.py b/tests/test_github.pyindex e3ee2510..7ca2c597 100644--- a/tests/test_github.py+++ b/tests/test_github.py@@ -574,6 +574,7 @@ class TestSearchGithubQualifiers(unittest.TestCase):def _capturing_fetch(self, captured):def fake_fetch(url, *args, **kwargs):captured["url"] = url+ captured.setdefault("urls", []).append(url)return {"total_count": 0, "items": []}return fake_fetch@@ -590,9 +591,86 @@ class TestSearchGithubQualifiers(unittest.TestCase):"open source ai stars:>1000 created:>2025-03-20","2026-07-01", "2026-07-31",)- q = self._query(captured["url"])- self.assertEqual(q, "open source ai created:>2026-07-01")- self.assertEqual(q.count("created:"), 1)+ queries = [self._query(u) for u in captured["urls"]]+ # Authenticated searches must carry `is:issue` or `is:pull-request`+ # (GitHub 422s without one), so the subject is asserted per sub-query+ # rather than against a single exact string.+ self.assertEqual(len(queries), 2)+ for q in queries:+ self.assertTrue(q.startswith("open source ai created:>2026-07-01"))+ self.assertEqual(q.count("created:"), 1)+ self.assertNotIn("stars:", q)+ self.assertEqual(+ {q.rsplit(" ", 1)[-1] for q in queries},+ {"is:issue", "is:pull-request"},+ )++ @patch.object(github, "_resolve_token", return_value="test-token")+ def test_authenticated_search_merges_issues_and_pull_requests(self, mock_token):+ """Both qualifier queries run, and their results are deduped and+ re-sorted by reactions — a plain concatenation would let the second+ query's tail outrank the first query's head."""+ issue = {"id": 1, "reactions": {"total_count": 5}}+ pull = {"id": 2, "reactions": {"total_count": 9}}+ also_issue = {"id": 1, "reactions": {"total_count": 5}} # cross-query dupe++ def fake_fetch(url, *args, **kwargs):+ q = self._query(url)+ if "is:issue" in q:+ return {"items": [issue]}+ return {"items": [pull, also_issue]}++ with patch.object(github, "_fetch_json", side_effect=fake_fetch):+ envelope = github.search_github("topic", "2026-07-01", "2026-07-31")++ ids = [item["id"] for item in envelope["items"]]+ self.assertEqual(ids, [2, 1], "expected reaction-sorted, deduped merge")++ @patch.object(github, "_resolve_token", return_value="test-token")+ def test_authenticated_search_one_partition_fails_keeps_items_and_reports_error(self, mock_token):+ """If one authenticated partition fails (returns None) and the other+ returns items, the surviving items are kept but the envelope carries+ an error so the source is not marked as a clean success."""+ issue = {"id": 1, "reactions": {"total_count": 5}}++ def fake_fetch(url, *args, **kwargs):+ q = self._query(url)+ if "is:issue" in q:+ return {"items": [issue]}+ return None # PR partition failed++ with patch.object(github, "_fetch_json", side_effect=fake_fetch):+ envelope = github.search_github("topic", "2026-07-01", "2026-07-31")++ self.assertEqual(len(envelope["items"]), 1)+ self.assertEqual(envelope["items"][0]["id"], 1)+ self.assertIn("error", envelope)+ self.assertIn("is:pull-request", envelope["error"])+ self.assertIn("partition", envelope["error"].lower())++ @patch.object(github, "_resolve_token", return_value="test-token")+ def test_authenticated_search_both_partitions_fail_is_full_failure(self, mock_token):+ """If both authenticated partitions fail (return None), the envelope+ has empty items and carries an error indicating complete failure."""++ with patch.object(github, "_fetch_json", return_value=None):+ envelope = github.search_github("topic", "2026-07-01", "2026-07-31")++ self.assertEqual(envelope["items"], [])+ self.assertIn("error", envelope)+ self.assertIn("GitHub", envelope["error"])++ @patch.object(github, "_resolve_token", return_value=None)+ def test_unauthenticated_search_omits_qualifier(self, mock_token):+ """Anonymous /search/issues is still grandfathered without a+ qualifier, so the single-query path must stay qualifier-free."""+ captured = {}+ with patch.object(github, "_fetch_json", side_effect=self._capturing_fetch(captured)):+ github.search_github("open source ai", "2026-07-01", "2026-07-31")+ self.assertEqual(len(captured["urls"]), 1)+ q = self._query(captured["urls"][0])+ self.assertNotIn("is:issue", q)+ self.assertNotIn("is:pull-request", q)@patch.object(github, "_resolve_token", return_value="test-token")def test_qualifier_only_topic_errors_without_network(self, mock_token):