--- tags: Node.js 直播班 - 2022 春季班 --- # Node.js 直播班小組 GitHub Flow 流程演練分享 ## 開發流程 ### 流程一:練習發 PR 1. 我先寫一小段並 push 上去 2. 同學 A clone 下來,開 feature 分支,並 push 上去,並發 PR 3. 我 PR 審核通過 :::spoiler postTodo.js ```=JavaScript const { v4: uuidv4 } = require('uuid'); const { successHandler, errorHandler } = require('./responseHandler'); const { message } = require('./libs') /** 新增單筆代辦 * @param data requestListener 資訊與清單物件 */ const postTodo = (data) => { const { req, res, todos } = data; /** http 傳來的 body 資訊 */ let body = ""; // 監聽 req 當 req 收到片段的 chunk 時,將片段資料加入 body 內。 req.on('data', chunk => { body += chunk; }); // 監聽 req 當 req 收完資料時,執行新增單筆代辦的功能 req.on('end', () => { const { wrongColumn, postFail } = message try { const title = JSON.parse(body).title; if (title !== undefined) { const todo = { title, 'id': uuidv4(), }; todos.push(todo); successHandler(res, todos); } else { errorHandler(res, 400, wrongColumn); } } catch { errorHandler(res, 400, postFail); } }); }; module.exports = postTodo; ``` ::: ### 流程二:rebase 練習 1. 同學A開新 feature 繼續寫下一個功能 2. 同學A寫的過程,我會偷偷在 main 上開新的 commit 3. 同學A會先 fetch main 的資料下來後,執行 rebase 指令並 push,才發 pr 4. 我 PR 審核通過 :::spoiler patchTodo.js ```=JavaScript const { successHandler, errorHandler } = require('./responseHandler'); const { message } = require('./libs') /** 編輯單筆代辦 * @param data requestListener 資訊與清單物件 */ const patchTodo = (data) => { const { req, res, todos } = data; /** http 傳來的 body 資訊 */ let body = ""; // 監聽 req 當 req 收到片段的 chunk 時,將片段資料加入 body 內。 req.on('data', chunk => { body += chunk; }); // 監聽 req 當 req 收完資料時,執行新增單筆代辦的功能 req.on('end', () => { const { noData, wrongColumn } = message try { const { title } = JSON.parse(body); if (title) { const id = req.url.split('/').pop(); const index = todos.findIndex((todo) => todo.id === id); if (index !== -1) { todos[index].title = title; successHandler(res, todos); } else { errorHandler(res, 400, noData); } } else { errorHandler(res, 400, wrongColumn); } } catch (err) { errorHandler(res, 400, err.message); } }); }; module.exports = patchTodo; ``` ::: ### 流程三:線上解衝突情境 1. 都 fetch 最新的下來 2. 同學A跟同學B各開新 feature ,都改同一行 code 並發 PR。server.js 第八行 3. 我審核同學A的通過,但同學B審核不通過 4. 同學B fetch 更新 main,在自己本地端下 rebase 後重發 PR <!-- ## 總結小組行為 * 組長開 repo 邀請各組員、建立一個 HackMD 文件,裡面建立各週的小組任務文件 * 約時間討論, * 同步:一起做作業、一起做小組任務(適合週六日、平日晚上) * 非同步:定期回報進度(適合平日) * 拆分工作內容 * 組員挑選任務內容,並依序發 PR * 挑選一個人去審核 PR * 訂定交付點里程碑 (例如最後一個組員發完 PR 並審核通過) -->