Skip to content

Commit f717184

Browse files
committed
add: GitHub Actions for issue tracking, Shopee API announcements, and workflow updates
1 parent 8dd2a41 commit f717184

9 files changed

Lines changed: 279 additions & 17 deletions

File tree

.ai/mcp/mcp.json

Lines changed: 0 additions & 10 deletions
This file was deleted.

.github/workflows/junie.yaml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Junie
2+
3+
on:
4+
issue_comment:
5+
types: [created]
6+
pull_request_review_comment:
7+
types: [created]
8+
issues:
9+
types: [opened, assigned]
10+
pull_request_review:
11+
types: [submitted]
12+
13+
jobs:
14+
junie:
15+
if: |
16+
(github.event_name == 'issue_comment' && contains(github.event.comment.body, '@junie-agent')) ||
17+
(github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '@junie-agent')) ||
18+
(github.event_name == 'pull_request_review' && contains(github.event.review.body, '@junie-agent')) ||
19+
(github.event_name == 'issues' && (contains(github.event.issue.body, '@junie-agent') || contains(github.event.issue.title, '@junie-agent')))
20+
runs-on: ubuntu-latest
21+
permissions:
22+
contents: write
23+
pull-requests: write
24+
issues: write
25+
steps:
26+
- name: Checkout repository
27+
uses: actions/checkout@v4
28+
with:
29+
fetch-depth: 1
30+
31+
- name: Run Junie
32+
id: junie
33+
uses: JetBrains/junie-github-action@v0
34+
with:
35+
junie_api_key: ${{ secrets.JUNIE_API_KEY }}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Check Shopee API Updates
2+
3+
# Configure scheduled and manual workflow runs
4+
on:
5+
schedule:
6+
- cron: '0 0 * * *' # Runs automatically at 00:00 UTC every day (around 07:00 Vietnam time)
7+
workflow_dispatch: # Allows manually clicking the "Run workflow" button in the GitHub UI for testing anytime
8+
9+
# PERMISSIONS: Required so GITHUB_TOKEN can create issues successfully
10+
permissions:
11+
issues: write
12+
contents: write
13+
14+
jobs:
15+
check-and-notify:
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
# Step 1: Pull source code from the repository to the GitHub Runner VM
20+
- name: Checkout repository code
21+
uses: actions/checkout@v4
22+
23+
# Step 2: Set up the PHP environment (choose a version compatible with your library)
24+
- name: Setup PHP environment
25+
uses: shivammathur/setup-php@v2
26+
with:
27+
php-version: '8.2'
28+
extensions: json, curl # Ensure curl and json extensions are enabled for the script
29+
30+
# Step 3: Run the Shopee scraping script, convert HTML to English Markdown, and filter language duplicates
31+
# Check duplicates via API and create an issue using GitHub CLI (gh)
32+
- name: Process Shopee Announcement and Create GitHub Issue
33+
env:
34+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Required variable for automatic authentication in gh CLI and GitHub API
35+
REPOSITORY_NAME: ${{ github.repository }}
36+
run: php bin/shopee-openapi-announcement

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@
22
/.idea/
33
composer.lock
44
.phpunit.result.cache
5-
/.junie

.junie/mcp/mcp.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"mcpServers": {
3+
"shopee": {
4+
"command": "php",
5+
"args": [
6+
"bin/shopee-mcp-server"
7+
]
8+
}
9+
}
10+
}
Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
---
2-
name: shopee-api-doc-first
2+
name: shopee-api
33
description: For any Shopee API related task, look up API documentation first via the Shopee MCP server before analyzing or implementing changes.
44
---
55

6-
# Shopee API Doc-First Skill
6+
# Shopee API Skill
77

88
Use this skill whenever the task touches Shopee API behavior, endpoint names, request parameters, response fields, auth flow, or SDK resource/API mapping.
99

@@ -14,20 +14,26 @@ Use this skill whenever the task touches Shopee API behavior, endpoint names, re
1414
- `mcp_shopee_search_documents`
1515
- Query by exact API name first when available (example: `v2.order.get_order_list`), then by keywords if needed.
1616

17-
2. **Ground decisions in docs**
17+
2. **When working with multiple APIs, lookup each API separately**
18+
- If the task touches more than one Shopee API, run `mcp_shopee_search_documents` for **each API at the moment you start working on that API**.
19+
- Do not reuse one API lookup as proof for another API.
20+
- Prefer exact API names per lookup (for example: `v2.product.get_item_base_info`, then `v2.logistics.get_shipping_parameter`).
21+
22+
3. **Ground decisions in docs**
1823
- Use the documentation lookup result as the source of truth for:
1924
- endpoint/API names
2025
- required and optional request parameters
2126
- response field expectations
2227
- related Shopee resource/module
2328

24-
3. **Then implement or answer**
29+
4. **Then implement or answer**
2530
- Only after documentation lookup, proceed to explanation, code changes, or tests.
2631
- If docs are missing or unclear, explicitly state that limitation and use the closest verified SDK reference.
2732

2833
## Practical checklist
2934

3035
- [ ] Shopee MCP docs search was executed before implementation/analysis.
36+
- [ ] For multi-API tasks, a separate Shopee MCP docs search was executed for each API when that API work started.
3137
- [ ] Exact API name was used in query when known.
3238
- [ ] Final answer/change aligns with documented request/response structure.
33-
- [ ] Any documentation gaps are called out explicitly.
39+
- [ ] Any documentation gaps are called out explicitly.

bin/shopee-mcp-install

100644100755
File mode changed.

bin/shopee-openapi-announcement

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
#!/usr/bin/env php
2+
<?php
3+
declare(strict_types=1);
4+
5+
const SHOPEE_API_URL = 'https://open.shopee.com/opservice/api/v1';
6+
7+
// get shopee openapi updates list
8+
$shopee_openapi_updates = curl_get(SHOPEE_API_URL.'/content/list?SPC_CDS_VER=2&category_id=55&page_size=10&page_index=1');
9+
$shopee_openapi_updates = json_decode($shopee_openapi_updates, true);
10+
11+
// latest announcement
12+
$latest_announcement = $shopee_openapi_updates['data'][0] ?? null;
13+
14+
if (!$latest_announcement) {
15+
die("No announcement found.");
16+
}
17+
18+
$announcement_id = $latest_announcement['id'];
19+
$announcement_title = $latest_announcement['title'];
20+
$repo = getenv('GITHUB_REPOSITORY');
21+
$unique_flag = "[Shopee-ID:{$announcement_id}]";
22+
23+
echo "Checking Issue for announcement ID: {$announcement_id}\n\n";
24+
$search_query = urlencode("\"{$unique_flag}\" repo:{$repo} is:issue");
25+
$api_url = "https://api.github.com/search/issues?q={$search_query}";
26+
27+
$search_result = curl_get($api_url, getenv('GITHUB_TOKEN'));
28+
29+
// checking if issue already exists
30+
if (isset($searchResult['total_count']) && $searchResult['total_count'] > 0) {
31+
echo "Issue already exists for announcement ID: {$announcement_id}\n\n";
32+
exit;
33+
}
34+
35+
// get announcement content
36+
$latest_announcement_data = curl_get(SHOPEE_API_URL.'/content/detail?SPC_CDS_VER=2&id='.$latest_announcement['id']);
37+
$latest_announcement_data = json_decode($latest_announcement_data, true);
38+
39+
// announcement content
40+
$blocks = json_decode($latest_announcement_data['detail'], true);
41+
$markdownOutput = convertShopeeJsonToEnglishMarkdown($blocks);
42+
43+
echo "No Issue found. Creating new Issue for announcement ID: {$announcement_id}\n\n";
44+
$issue_title = "{$announcement_title} {$unique_flag}";
45+
$issue_body = <<<MARKDOWN
46+
## New Shopee's Openapi Announcement (ID: {$announcement_id})
47+
48+
{$markdownOutput}
49+
50+
---
51+
@junie-agent Please check the changes for this endpoint in Shopee's Openapi Announcement, update the corresponding PHP source code in the repo, and create a new Pull Request for review.
52+
MARKDOWN;
53+
54+
echo $markdownOutput;exit;
55+
56+
function curl_get($url, $github_token = null)
57+
{
58+
$ch = curl_init();
59+
curl_setopt($ch, CURLOPT_URL, $url);
60+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
61+
curl_setopt($ch, CURLOPT_USERAGENT, 'Shopee-Automation-Script');
62+
63+
if ($github_token) {
64+
curl_setopt($ch, CURLOPT_HTTPHEADER, ["Authorization: Bearer {$github_token}"]);
65+
}
66+
67+
$output = curl_exec($ch);
68+
curl_close($ch);
69+
70+
return json_decode($output, true);
71+
}
72+
73+
function parseHtmlTableToMarkdown(string $htmlTable): string
74+
{
75+
// Extract all table rows.
76+
if (!preg_match_all('/<tr[^>]*>(.*?)<\/tr>/is', $htmlTable, $rows)) {
77+
return '';
78+
}
79+
80+
$markdownRows = [];
81+
$isHeader = true;
82+
$lineBreaks = ['<br />', '<br>', "\n", "\r"];
83+
84+
foreach ($rows[1] as $rowHtml) {
85+
// Extract all th/td cells from the current row.
86+
if (!preg_match_all('/<(th|td)[^>]*>(.*?)<\/\1>/is', $rowHtml, $cells)) {
87+
continue;
88+
}
89+
90+
$cleanCells = [];
91+
foreach ($cells[2] as $cell) {
92+
// Remove nested tags, normalize whitespace and keep <code> tags.
93+
$cell = strip_tags($cell, '<code>');
94+
$cell = str_replace($lineBreaks, ' ', $cell);
95+
$cleanCells[] = trim((string) preg_replace('/\s+/', ' ', $cell));
96+
}
97+
98+
if ($cleanCells === []) {
99+
continue;
100+
}
101+
102+
$markdownRows[] = '| ' . implode(' | ', $cleanCells) . ' |';
103+
104+
// For the first row (header), append markdown separator.
105+
if ($isHeader) {
106+
$alignments = array_fill(0, count($cleanCells), '---');
107+
$markdownRows[] = '| ' . implode(' | ', $alignments) . ' |';
108+
$isHeader = false;
109+
}
110+
}
111+
112+
return implode("\n", $markdownRows) . "\n";
113+
}
114+
115+
/**
116+
* Convert Shopee JSON blocks into English markdown.
117+
*/
118+
function convertShopeeJsonToEnglishMarkdown(array $blocks): string
119+
{
120+
$markdown = "";
121+
$containsChinesePattern = '/[\x{4e00}-\x{9fa5}]+/u';
122+
123+
foreach ($blocks as $block) {
124+
$type = $block['type'] ?? '';
125+
$html = $block['html'] ?? '';
126+
127+
// --- LANGUAGE FILTERING STEP ---
128+
// Stop once Chinese translation blocks start, to keep only English content.
129+
if (strpos($html, '尊敬的开发者') || preg_match($containsChinesePattern, $html) === 1) {
130+
break;
131+
}
132+
133+
// --- HTML TO MARKDOWN CONVERSION ---
134+
switch ($type) {
135+
case 'heading':
136+
// Convert heading tags to markdown heading syntax.
137+
$cleanText = strip_tags($html);
138+
$markdown .= "## " . trim($cleanText) . "\n\n";
139+
break;
140+
141+
case 'table':
142+
$markdown .= parseHtmlTableToMarkdown($html) . "\n";
143+
break;
144+
145+
case 'text':
146+
// Handle ordered lists (<ol><li>).
147+
if (strpos($html, '<ol>')) {
148+
preg_match_all('/<li>(.*?)<\/li>/is', $html, $lis);
149+
foreach ($lis[1] as $index => $li) {
150+
$cleanLi = strip_tags($li, '<a><code>');
151+
// Convert <a> tags to markdown links.
152+
$cleanLi = preg_replace('/<a href="([^"]+)">([^<]+)<\/a>/i', '[$2]($1)', $cleanLi);
153+
$markdown .= ($index + 1) . ". " . trim($cleanLi) . "\n";
154+
}
155+
$markdown .= "\n";
156+
} else {
157+
// Handle normal text paragraphs and break lines.
158+
$html = str_replace(['<br />', '<br>'], "\n", $html);
159+
160+
// Convert inline <a> links.
161+
$html = preg_replace('/<a href="([^"]+)"[^>]*>([^<]+)<\/a>/i', '[$2]($1)', $html);
162+
163+
// Convert bold/italic tags to markdown markers, keep <code>.
164+
$html = preg_replace('/<\/?b[^>]*>/i', '**', $html);
165+
$html = preg_replace('/<\/?i[^>]*>/i', '*', $html);
166+
167+
// Remove remaining HTML tags except <code>.
168+
$cleanText = strip_tags($html, '<code>');
169+
170+
// Normalize HTML entities (for example, &amp; to &).
171+
$cleanText = html_entity_decode($cleanText);
172+
173+
if (trim($cleanText) !== '') {
174+
$markdown .= trim($cleanText) . "\n\n";
175+
}
176+
}
177+
break;
178+
}
179+
}
180+
181+
// Remove excessive blank lines.
182+
return trim(preg_replace("/\n{3,}/", "\n\n", $markdown));
183+
}
184+
185+
?>

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"type": "library",
55
"bin": [
66
"bin/shopee-mcp-server",
7-
"bin/shopee-mcp-install"
7+
"bin/shopee-mcp-install",
8+
"bin/shopee-openapi-announcement"
89
],
910
"license": "Apache-2.0",
1011
"authors": [

0 commit comments

Comments
 (0)