====== Subversion 與 Mantis 整合作法 ====== ===== 目標 ===== 當 Mantis 有張貼一個新的 Issue 時, 與這個 Issue 相關的 Subversion 更動紀錄可以自動回寫至 Mantis 這個 Issue 內的 Bug 筆記內. ===== 相關環境 ===== * Mantis 與 Subversion 都安裝在相同的主機上 * 作業系統為 CentOS release 6.9 x86_64 * Mantis 版本為 2.8.0 安裝在 /var/www/html/mantis * Subversion 版本為 1.6.11-15 * SVN 資料檔案路徑 /var/www/svn/ * 因為 Mantis 2.x 無法在 core 目錄底下找到 checkin.php * 需要改用 plugin - https://github.com/mantisbt-plugins/source-integration 來整合 * 如果要參考之前的紀錄, 請至 [[tech/svnmantis1x]] ===== 安裝 plugin - source-integration ===== * 下載最新版 plugin cd /var/www/html/mantis/plugins/ wget https://github.com/mantisbt-plugins/source-integration/archive/master.zip unzip master.zip rm master.zip cd source-integration-master/ cp -a Source .. cp -a SourceSVN .. ===== 設定程序 ===== ==== Mantis 管理介面設定 ==== * 至 Mantis 管理->管理套件->可用的套件 安裝 ++看畫面|{{:tech:2018032601.png|}}++ * Source Control Integration 2.1.0 * Source Subversion Integration 2.1.0 * 在 已安裝的套件 點 Source Control Integration 2.1.0 進行設定 * 因為我習慣在 svn 說明內打 mantis#123 這樣的方式來表示對 #123 的問題進行更新, 所以會修改以下的 Regex ++看畫面|{{:tech:2018032602.png|}}++ * Bug Link Regex Pass 1 : /\b(?:bug|issue|mantis)\s*[#]{0,1}(\d+)\b/i * Bug Fixed Regex Pass 1 : /\bfix(?:ed|es)\s+(?:bug|issue|mantis)?\s*[#]{0,1}(\d+)\b/i * 透過 openssl rand -hex 12 來產生 API Key (之後會用到) * 如果是自發憑證, 會出現檢核憑證失敗的問題, 此時需要先檢視憑證的 CN , 網址要設定成這 CN 網址才能通過檢核 Exp. kvm-SVN -> https://kvm-SVN/repos/xxxx ++看畫面|{{:tech:2018032603.png|}}++ * 在左邊的選項會多出 Repositories ++看畫面|{{:tech:2018032604.png|}}++ * 建立一個對應 SVN 專案 Exp. erptools ++看畫面|{{:tech:2018032605.png|}}++ * 建立後輸入 SVN 的 URL Exp. https://kvm-SVN/repos/erptools (可先用正常的網址, 出現 https 憑證無法通過時, 再改用 https 憑證內的 CN 當網址, 記得在 /etc/hosts 內也要設定好) * 即使在 SVN: Command arguments 有指定 --config-dir 還是需要輸入 SVN Username / SVN Password ==== 主機端設定 ==== * 複製 post-commit.tmpl 到 SVN 專案 erptools 的 hooks 目錄內, 並改名為 post-commit cp -a /var/www/html/mantis/plugins/SourceSVN/post-commit.tmpl /var/www/svn/erptools/hooks/post-commit chmod a+x /var/www/svn/erptools/hooks/post-commit * 修改 post-commit 內容符合實際環境 vi /var/www/svn/erptools/hooks/post-commit #!/bin/sh # Copyright (c) 2012 John Reese # Licensed under the MIT license REV="$2" URL="http://localhost/mantis/plugin.php?page=Source/checkin" PROJECT="erptools" API_KEY="xxxxxxxxxxxxxxxx" LOG_FILE=`mktemp /tmp/svn_${PROJECT}_${REV}_log.XXX` CURL=/usr/bin/curl ${CURL} -d "repo_name=${PROJECT}" -d "data=${REV}" -d "api_key=${API_KEY}" ${URL} >> ${LOG_FILE} 主要修改 * URL (Mantis 網址) * API_KEY (在上面透過 openssl rand -hex 12 產生長度 24 的字串) ===== 測試整合 ===== * 只要 SubVersion 內的紀錄出現 bug 或 issue 或 mantis #編號 表示整合 Mantis 內的 Issue # Bug 筆記 * 只要 SubVersion 內的紀錄出現 fixed 或 fixes + bug 或 issue 或 mantis #編號 表示整合 Mantis 內的 Issue # Bug 筆記外, 更會將 issue 狀態改成已修正解決 * 如果之前在 svn 內的 commit 描述有出現 mantis# 就可以透過以下命令直接測試 Exp. svn#325 curl -d "repo_name=erptools" -d "data=325" -d "api_key=xxxxxxxxxxxxxxxxxxxxxxxx" "http://localhost/mantis/plugin.php?page=Source/checkin" * 結果如以下畫面: * 如果成功整合, Repositories 的 Changesets, Files, Issues 就會出現數值 \\ {{:tech:2018032606.png}} * 點進去看 Changesets , 可以看到是否有對應到 Mantis 的 Issue, 沒對應到也可以手動 Attach 上去 \\ {{:tech:2018032607.png}} * 點到 Mantis 問題(Issue)頁面, 可以看到多一個 Related Changesets 項目, 紀錄 SVN 整合到這 Issue 的訊息 \\ {{:tech:2018032608.png}} **如果這個步驟沒有正確在 Repositories 的 Changesets 看到, 那就需要到 Server 端 /tmp 查看 log 狀況** ===== 參考資料 ===== * https://github.com/mantisbt-plugins/source-integration/blob/master/README.md * https://github.com/mantisbt-plugins/source-integration/blob/master/docs/CONFIGURING.SourceSVN.md {{tag>類型:軟體工程 狀態:已發行 svn subversion mantis 密技}}