From ad9bfacedd895976554216f6ad0d127e5bd62d6d Mon Sep 17 00:00:00 2001 From: Sun Date: Thu, 29 Feb 2024 14:18:44 +0800 Subject: [PATCH 01/10] doc: add title's description and branch warning in pr template --- .github/pull_request_template.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 78b908d9..1d79d8c9 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -7,9 +7,9 @@ -- [ ] A clear title +- [ ] A clear title (name your pr "[LAB{lab_number}] {your_student_id}") - [ ] A meaningful message for PR, as well as its commits -- [ ] From your specific branch (***not master***) merging to your branch +- [ ] From your specific branch (***not main or other's branch***) merging to your branch - [ ] Excluding any irrelevant files, such as binaries, text files, or dot files - [ ] Passing tests/CI - [ ] Add proper label for this PR From a5a9797bd7bc598c63163a29fca374837fd0ccc7 Mon Sep 17 00:00:00 2001 From: Sun Date: Thu, 29 Feb 2024 14:19:05 +0800 Subject: [PATCH 02/10] feat: remove badge requirement in lab1 --- lab1/README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lab1/README.md b/lab1/README.md index f205b0b9..779166ca 100644 --- a/lab1/README.md +++ b/lab1/README.md @@ -6,8 +6,7 @@ In this lab, you will write unit tests for functions implemented in `main.js`. Y ## Requirement -1. Write test cases in `main_test.js` and achieve 100% code coverage. (90%) -2. Add a badge and make it show `passing` in `README.md` in the root folder. (10%) +1. Write test cases in `main_test.js` and achieve 100% code coverage. (100%) You can run `validate.sh` in your local to test if you satisfy the requirements. From 01554ce0d9f96bc7afbc80cb7cdfadb0610910df Mon Sep 17 00:00:00 2001 From: Sun Date: Thu, 29 Feb 2024 14:21:46 +0800 Subject: [PATCH 03/10] doc: add sample's link in pr template --- .github/pull_request_template.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 1d79d8c9..fa079b42 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -1,5 +1,8 @@ ## Description + + + --- From d418b85c2841bae307731c7c8f241cdaf43f6939 Mon Sep 17 00:00:00 2001 From: Sun Date: Thu, 29 Feb 2024 16:07:43 +0800 Subject: [PATCH 04/10] feat: add automatic PR labeler in github workflow --- .github/workflows/label.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 .github/workflows/label.yml diff --git a/.github/workflows/label.yml b/.github/workflows/label.yml new file mode 100644 index 00000000..12a22b04 --- /dev/null +++ b/.github/workflows/label.yml @@ -0,0 +1,23 @@ +name: Automatic PR Labeler +on: + pull_request: + types: [opened, reopened, edited] + +jobs: + labeler: + runs-on: ubuntu-latest + steps: + - name: Label PR + uses: actions/github-script@v5 + with: + script: | + const { owner, repo, number: issue_number } = context.issue; + const pr = await github.rest.pulls.get({ owner, repo, pull_number: issue_number }); + const title = pr.data.title; + const labRegex = /\[LAB(\d+)\]/i; + + const match = title.match(labRegex); + if (match) { + const labelToAdd = 'lab' + match[1]; + await github.rest.issues.addLabels({ owner, repo, issue_number, labels: [labelToAdd] }); + } From 9671d55b35787cde9325f4fbd43e60191187fd29 Mon Sep 17 00:00:00 2001 From: Sun Date: Thu, 29 Feb 2024 19:15:46 +0800 Subject: [PATCH 05/10] feat: update labeler's event and add github-token --- .github/workflows/label.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/label.yml b/.github/workflows/label.yml index 12a22b04..4e7902a5 100644 --- a/.github/workflows/label.yml +++ b/.github/workflows/label.yml @@ -1,6 +1,6 @@ name: Automatic PR Labeler on: - pull_request: + pull_request_target: types: [opened, reopened, edited] jobs: @@ -10,6 +10,7 @@ jobs: - name: Label PR uses: actions/github-script@v5 with: + github-token: ${{ secrets.PAT }} script: | const { owner, repo, number: issue_number } = context.issue; const pr = await github.rest.pulls.get({ owner, repo, pull_number: issue_number }); From 332349a0c74c3a812b57530cdecb34104f575507 Mon Sep 17 00:00:00 2001 From: Sun Date: Thu, 29 Feb 2024 19:23:07 +0800 Subject: [PATCH 06/10] fix: validate.sh will failed if there are spaces in node's path --- lab1/validate.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lab1/validate.sh b/lab1/validate.sh index dca233b1..d64ed954 100755 --- a/lab1/validate.sh +++ b/lab1/validate.sh @@ -9,7 +9,7 @@ cd $tmp_dir rm -rf * cp $solution_path/*.js . -result=$($node --test --experimental-test-coverage) ; ret=$? +result=$($"node" --test --experimental-test-coverage) ; ret=$? if [ $ret -ne 0 ] ; then echo "[!] testing fails" exit 1 From 69cf109ebbb62cf01ec9c162ce3f3590972a6096 Mon Sep 17 00:00:00 2001 From: Sun Date: Thu, 29 Feb 2024 19:28:03 +0800 Subject: [PATCH 07/10] doc: remove label instruction in pr template --- .github/pull_request_template.md | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index fa079b42..ab8eabd5 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -15,4 +15,3 @@ - [ ] From your specific branch (***not main or other's branch***) merging to your branch - [ ] Excluding any irrelevant files, such as binaries, text files, or dot files - [ ] Passing tests/CI -- [ ] Add proper label for this PR From 65f28276bddf45816422446462dfec9e64e73f0e Mon Sep 17 00:00:00 2001 From: Sun Date: Thu, 29 Feb 2024 21:19:09 +0800 Subject: [PATCH 08/10] feat: add script to rebase all branches --- scripts/rebase-all.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 scripts/rebase-all.sh diff --git a/scripts/rebase-all.sh b/scripts/rebase-all.sh new file mode 100644 index 00000000..4e384871 --- /dev/null +++ b/scripts/rebase-all.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +git fetch origin + +for branch in $(git branch -r | grep -v HEAD); do + # Remove the "origin/" prefix + branch=${branch#origin/} + + if [[ "$branch" != "main" ]]; then + git checkout "$branch" + git pull origin "$branch" + git rebase main + git push origin "$branch" + fi +done + +git checkout main \ No newline at end of file From 4f22b9d2429d079e98a7e2e28d1407b47b1d6cb7 Mon Sep 17 00:00:00 2001 From: Sun Date: Thu, 29 Feb 2024 21:46:41 +0800 Subject: [PATCH 09/10] feat: exit when failed in rebase-all script --- scripts/rebase-all.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/scripts/rebase-all.sh b/scripts/rebase-all.sh index 4e384871..26eef16b 100644 --- a/scripts/rebase-all.sh +++ b/scripts/rebase-all.sh @@ -8,8 +8,20 @@ for branch in $(git branch -r | grep -v HEAD); do if [[ "$branch" != "main" ]]; then git checkout "$branch" + if [[ $? -ne 0 ]]; then + echo "Checkout failed for branch $branch" + exit 1 + fi git pull origin "$branch" + if [[ $? -ne 0 ]]; then + echo "Pull failed for branch $branch" + exit 1 + fi git rebase main + if [[ $? -ne 0 ]]; then + echo "Rebase failed for branch $branch" + exit 1 + fi git push origin "$branch" fi done From 2f9f3c35b364741324028b739fbfdc4abf9556e5 Mon Sep 17 00:00:00 2001 From: emily Date: Thu, 29 Feb 2024 22:04:46 +0800 Subject: [PATCH 10/10] submit lab1 --- lab1/main_test.js | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/lab1/main_test.js b/lab1/main_test.js index 74a716b4..b843011e 100644 --- a/lab1/main_test.js +++ b/lab1/main_test.js @@ -3,21 +3,45 @@ const assert = require('assert'); const { MyClass, Student } = require('./main'); test("Test MyClass's addStudent", () => { - // TODO - throw new Error("Test not implemented"); + const myClass = new MyClass(); + const jason = new Student(); + const mary = new Student(); + assert.strictEqual(0, myClass.addStudent(jason)); + assert.strictEqual(1, myClass.addStudent(mary)); + assert.strictEqual(-1, myClass.addStudent(123)); }); test("Test MyClass's getStudentById", () => { - // TODO - throw new Error("Test not implemented"); + const myClass = new MyClass(); + const student = new Student(); + const names = ['John', 'Jane', 'Doe', 'Smith']; + names.forEach(name => { + const student = new Student(); + student.setName(name); + const newStudentId = myClass.addStudent(student); + const newStudentName = myClass.getStudentById(newStudentId).getName(); + }); + assert.strictEqual(myClass.getStudentById(-2), null); + assert.strictEqual(myClass.getStudentById(0).getName(), 'John'); + assert.strictEqual(myClass.getStudentById(1).getName(), 'Jane'); + assert.strictEqual(myClass.getStudentById(2).getName(), 'Doe'); + assert.strictEqual(myClass.getStudentById(3).getName(), 'Smith'); + assert.strictEqual(myClass.getStudentById(4), null); }); test("Test Student's setName", () => { - // TODO - throw new Error("Test not implemented"); + const student1 = new Student(); + const student2 = new Student(); + student1.setName('Jason') + assert.strictEqual(student1.name, 'Jason'); + student2.setName(234); + assert.strictEqual(student2.name, undefined); }); test("Test Student's getName", () => { - // TODO - throw new Error("Test not implemented"); + const student1 = new Student(); + const student2 = new Student(); + student1.setName('Mary'); + assert.strictEqual(student1.getName(), 'Mary'); + assert.strictEqual(student2.getName(), ''); }); \ No newline at end of file