├── .circleci ├── config.yml ├── verifyWhitelist.sh └── whitelist.txt ├── .github └── PULL_REQUEST_TEMPLATE.md ├── .gitignore ├── README.md ├── pom.xml └── src ├── main └── java │ └── Solution.java └── test └── java └── SolutionTest.java /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | jobs: 3 | test: 4 | docker: 5 | - image: circleci/openjdk:8u212-jdk-stretch 6 | steps: 7 | - checkout 8 | - restore_cache: 9 | key: hcsp-{{ checksum "pom.xml" }} 10 | - run: 11 | name: Verify whitelist 12 | command: ./.circleci/verifyWhitelist.sh 13 | - run: 14 | name: Run Maven verify 15 | command: mvn clean verify 16 | - save_cache: # saves the project dependencies 17 | paths: 18 | - ~/.m2 19 | key: hcsp-{{ checksum "pom.xml" }} 20 | workflows: 21 | version: 2 22 | default: 23 | jobs: 24 | - test 25 | -------------------------------------------------------------------------------- /.circleci/verifyWhitelist.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [ -z "${BASE_REV}" ]; then 4 | BASE="origin/master" 5 | else 6 | BASE="${BASE_REV}" 7 | fi 8 | 9 | CHANGED_FILES=`git diff --name-only $BASE...HEAD` 10 | 11 | CHANGED_FILE_LIST=($(echo "$CHANGED_FILES" | sed 's/"//g' | sed 's/:/ /g')) 12 | WHITELIST=($(cat .circleci/whitelist.txt | sed 's/"//g' | sed 's/:/ /g')) 13 | 14 | beginswith() { case $1 in "$2"*) true;; *) false;; esac; } 15 | 16 | endswith() { case $1 in *"$2") true;; *) false;; esac; } 17 | 18 | INDEX=1 19 | for file in "${CHANGED_FILE_LIST[@]}" 20 | do 21 | MATCHED=0 22 | 23 | for item in "${WHITELIST[@]}" 24 | do 25 | if endswith "$item" / && beginswith "$file" "$item"; then 26 | MATCHED=1 27 | break 28 | elif [ "$file" == "$item" ]; then 29 | MATCHED=1 30 | break 31 | fi 32 | done 33 | 34 | if [ "$MATCHED" == '0' ]; then 35 | RESULT[INDEX]=$file 36 | INDEX=$((INDEX+1)) 37 | fi 38 | 39 | done 40 | 41 | if [ ${#RESULT[@]} -ne 0 ]; then 42 | echo -e "We only allow the modification of these files:\n${WHITELIST[@]}\n\nThe files you modified:\n${RESULT[@]}" 43 | echo -e "\n--------------------\n" 44 | echo -e "我们只允许你修改以下文件:\n${WHITELIST[@]}\n\n但是你修改了:\n${RESULT[@]}\n" 45 | exit 1 46 | fi 47 | -------------------------------------------------------------------------------- /.circleci/whitelist.txt: -------------------------------------------------------------------------------- 1 | src/main/java/Solution.java 2 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | - [x] 这个PR解答了当前仓库中的题目(机器人会自动判题并合并当前PR) 4 | - [ ] 这个PR修复了当前仓库中的一些代码缺陷(机器人不会判题,而是由管理员来处理当前PR) 5 | 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | .gradle/ 3 | build/ 4 | out/ 5 | target/ 6 | *.iml 7 | 8 | # Eclipse 9 | .classpath 10 | .project 11 | .settings/ 12 | bin/ 13 | 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 学习GitHub的使用(通过IDEA或者Git命令行) 2 | 3 | [这里](https://github.com/hcsp/fix-add-function/blob/master/src/main/java/Solution.java)有一个明显的错误,请将其修正后提交Pull Request。在提交Pull Request之前,你应当在本地确保所有代码已经编译通过,并且通过了测试(`mvn clean verify`) 4 | 5 | ----- 6 | 注意!我们只允许你修改以下文件,对其他文件的修改会被拒绝: 7 | - [src/main/java/Solution.java](https://github.com/hcsp/fix-add-function/blob/master/src/main/java/Solution.java) 8 | ----- 9 | 10 | 11 | 完成题目有困难?不妨来看看[写代码啦的相应课程](https://xiedaimala.com/tasks/bd34186b-63f2-4e2d-9145-0c61e2cc0f63/video_tutorials/0378de3c-cfd0-4b2d-b8fc-d04b6f613777)吧! 12 | 13 | 回到[写代码啦的题目](https://xiedaimala.com/tasks/bd34186b-63f2-4e2d-9145-0c61e2cc0f63/quizzes/4d1d2c45-bbc3-499e-9550-f3e35066eecb),继续挑战! 14 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | hcsp 6 | fix-add-function 7 | 1.0-SNAPSHOT 8 | 9 | 10 | 1.8 11 | 1.8 12 | UTF-8 13 | 14 | 15 | 16 | 17 | alimaven 18 | aliyun maven 19 | http://maven.aliyun.com/nexus/content/groups/public/ 20 | 21 | 22 | 23 | 24 | org.junit.jupiter 25 | junit-jupiter-api 26 | 5.6.0 27 | test 28 | 29 | 30 | org.junit.jupiter 31 | junit-jupiter-engine 32 | 5.6.0 33 | test 34 | 35 | 36 | 37 | 38 | 39 | 40 | maven-surefire-plugin 41 | 2.22.1 42 | 43 | -Dfile.encoding=UTF-8 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /src/main/java/Solution.java: -------------------------------------------------------------------------------- 1 | public class Solution { 2 | public static int add(int a, int b) { 3 | return a - b; 4 | } 5 | 6 | public static void main(String[] args) { 7 | System.out.println("1+1=" + add(1, 1)); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/test/java/SolutionTest.java: -------------------------------------------------------------------------------- 1 | import org.junit.jupiter.api.Assertions; 2 | import org.junit.jupiter.api.Test; 3 | 4 | public class SolutionTest { 5 | @Test 6 | public void addTest() { 7 | Assertions.assertEquals(Solution.add(1, 1), 2); 8 | Assertions.assertEquals(Solution.add(1, 2), 3); 9 | Assertions.assertEquals(Solution.add(-1, 1), 0); 10 | Assertions.assertEquals(Solution.add(Integer.MAX_VALUE, Integer.MIN_VALUE), -1); 11 | } 12 | } 13 | --------------------------------------------------------------------------------