diff --git a/.github/workflows/generate-jira-excerpt.yml b/.github/workflows/generate-jira-excerpt.yml index cf7ececfa..9e0787fe7 100644 --- a/.github/workflows/generate-jira-excerpt.yml +++ b/.github/workflows/generate-jira-excerpt.yml @@ -1,4 +1,5 @@ name: "Pull from Armbian Jira" + on: repository_dispatch: types: ["Jira update"] @@ -11,36 +12,152 @@ jobs: jira: runs-on: ubuntu-24.04 name: "Get from Armbian Jira" - steps: + permissions: + contents: write + env: + JIRA_EMAIL: ${{ secrets.JIRA_EMAIL }} + JIRA_TOKEN: ${{ secrets.JIRA_TOKEN }} + steps: - name: Checkout repository uses: actions/checkout@v5 with: fetch-depth: 0 path: armbian.github.io - - name: setup python + - name: Setup Python uses: actions/setup-python@v6 with: - python-version: 3.8 #install the python needed + python-version: "3.10" - - name: "Run script" + - name: Install Python deps run: | - pip install jira - ./armbian.github.io/scripts/pull-from-jira.py + python -m pip install --upgrade pip + pip install requests - - name: Commit changes if any + - name: Pull from Jira (inline; same HTML as before) + shell: bash run: | + python - <<'PY' + # Emits identical structure to the previous pull-from-jira.py + import os, sys, html, requests + from datetime import datetime + + BASE = "https://armbian.atlassian.net" + SEARCH_URL = f"{BASE}/rest/api/3/search/jql" + EMAIL = os.environ.get("JIRA_EMAIL") + TOKEN = os.environ.get("JIRA_TOKEN") + if not EMAIL or not TOKEN: + print("Missing JIRA_EMAIL or JIRA_TOKEN", file=sys.stderr) + sys.exit(1) + + AUTH = (EMAIL, TOKEN) + HEADERS = {"Accept": "application/json"} + + # Icons exactly like before + def icons(arg: str) -> str: + s = str(arg) + if s == "Bug": + return '' + if s == "Task": + return '' + if s == "Story": + return '' + if s == "Epic": + return '' + return "" + + # Release buckets: 02,05,08,11 (match old logic) + now = datetime.now() + y = now.year + m = int(now.strftime("%m")) + if m <= 2: + current_year, current_month = y, "02" + next_year, next_month = y, "05" + elif m <= 5: + current_year, current_month = y, "05" + next_year, next_month = y, "08" + elif m <= 8: + current_year, current_month = y, "08" + next_year, next_month = y, "11" + elif m <= 11: + current_year, current_month = y, "11" + next_year, next_month = y+1, "02" + else: + current_year, current_month = y+1, "02" + next_year, next_month = y+1, "05" + + current_fix = f"{str(current_year)[2:]}.{current_month}" + next_fix = f"{str(next_year)[2:]}.{next_month}" + FIELDS = "summary,issuetype,assignee,priority,status" + + def fetch_all(jql: str, page=100): + start = 0 + out = [] + while True: + params = {"jql": jql, "fields": FIELDS, "startAt": start, "maxResults": page} + r = requests.get(SEARCH_URL, params=params, headers=HEADERS, auth=AUTH, timeout=30) + if r.status_code >= 400: + print(f"Jira API error {r.status_code}: {r.text}", file=sys.stderr) + sys.exit(1) + data = r.json() + chunk = data.get("issues", []) + out.extend(chunk) + total = data.get("total", len(out)) + if not chunk or start + len(chunk) >= total: + break + start += len(chunk) + return out + + # EXACT same top-matter as before (markdown-ish in .html) + def write_current(): + with open("jira-current.html", "w", encoding="utf-8") as f: + f.write('\n\n

Should be completed in ' + current_fix + '

Sorted by priority
\n') + f.write('\n
Check if you can review code that already waits at Pull reqests
\n') + f.write('
\n') + issues = fetch_all(f'project=AR and fixVersion="{current_fix}" and status!="Done" and status!="Closed" order by Priority') + for it in issues: + key = it.get("key") + fields = it.get("fields") or {} + itype = ((fields.get("issuetype") or {}).get("name")) or "" + summary = fields.get("summary") or "" + assignee = (fields.get("assignee") or {}).get("displayName") or "Unassigned" + f.write(f'\n{html.escape(key)} {icons(itype)} {html.escape(itype)}: {html.escape(summary)}, Assigned to: {html.escape(assignee)}') + f.write("\n") + f.write('
\n') + + def write_next(): + with open("jira-next.html", "w", encoding="utf-8") as f: + f.write('\n\n

Planned for ' + next_fix + '

Sorted by priority
\n') + f.write('
\n') + issues = fetch_all(f'project=AR and fixVersion="{next_fix}" and status!="Done" and status!="Closed" order by priority desc') + for it in issues: + key = it.get("key") + fields = it.get("fields") or {} + itype = ((fields.get("issuetype") or {}).get("name")) or "" + summary = fields.get("summary") or "" + assignee = (fields.get("assignee") or {}).get("displayName") or "Unassigned" + f.write(f'\n{html.escape(key)} {icons(itype)} {html.escape(itype)}: {html.escape(summary)}, Assigned to: {html.escape(assignee)}') + f.write("\n") + f.write('
\n') + + write_current() + write_next() + PY + + - name: Commit changes if any + shell: bash + run: | cd armbian.github.io git checkout data mkdir -p data/ mv ${{ github.workspace }}/jira-current.html data/ mv ${{ github.workspace }}/jira-next.html data/ - git config --global user.name "github-actions" - git config --global user.email "github-actions@github.com" + git config user.name "github-actions" + git config user.email "github-actions@github.com" git add data/. - git diff --cached --quiet || git commit -m "Update WEB indes files" + git diff --cached --quiet || git commit -m "Update WEB index files" git push - name: "Run pull from Repository action" @@ -48,3 +165,4 @@ jobs: with: token: ${{ secrets.GITHUB_TOKEN }} event-type: "Repository status" + diff --git a/scripts/pull-from-jira.py b/scripts/pull-from-jira.py deleted file mode 100755 index debdafe95..000000000 --- a/scripts/pull-from-jira.py +++ /dev/null @@ -1,71 +0,0 @@ -#!/usr/bin/env python3 -# -# automatic displaying of what is assigned to fixversion -# for current and next release - -from jira import JIRA -jira = JIRA('https://armbian.atlassian.net') - -from datetime import datetime -month = datetime.now().strftime('%m') -year = datetime.now().year - -def icons(arg): - if str(arg) == "Bug": - return ("Bug") - if str(arg) == "Task": - return ("Task") - if str(arg) == "Story": - return ("Story") - if str(arg) == "Epic": - return ("Epic''") - -if ( month <= "12" ): - current_year=year+1 - current_month="02" - next_month="05" - next_year=year+1 - -if ( month <= "11" ): - current_year=year - current_month="11" - next_month="02" - next_year=year+1 - -if ( month <= "08" ): - current_year=year - current_month="08" - next_month="11" - next_year=year - -if ( month <= "05" ): - current_year=year - current_month="05" - next_month="08" - next_year=year - -if ( month <= "02" ): - current_year=year - current_month="02" - next_month="05" - next_year=year - -# current -f = open("jira-current.html", "w") -current=str(current_year)[2:]+"."+current_month -f.write('
\n

Should be completed in '+current+'

Sorted by priority

\n

\n') -f.write('
\n
Check if you can review code that already waits at Pull reqests
\n
\n') -f.write('
\n') -for issue in jira.search_issues('project=AR and fixVersion="'+current+'" and status!="Done" and status!="Closed" order by Priority', maxResults=100): - f.write('\n{} {}: {}, Assigned to: {}'.format(issue.key, icons(issue.fields.issuetype), issue.fields.issuetype, issue.fields.summary, issue.fields.assignee )) -f.write('\n
\n'); -f.close() - -# next -f = open("jira-next.html", "w") -next=str(next_year)[2:]+"."+next_month -f.write('\n
\n

Planned for '+next+' and further

Sorted by priority

\n
') -for issue in jira.search_issues('project=AR and fixVersion="'+next+'" and status!="Done" and status!="Closed" order by priority desc', maxResults=100): - f.write('\n{} {}: {}, Assigned to: {}'.format(issue.key, icons(issue.fields.issuetype), issue.fields.issuetype, issue.fields.summary, issue.fields.assignee)) -f.write('\n
\n'); -f.close()