diff --git a/.github/workflows/checkcpp.yml b/.github/workflows/checkcpp.yml new file mode 100644 index 0000000..ee6f225 --- /dev/null +++ b/.github/workflows/checkcpp.yml @@ -0,0 +1,38 @@ +name: C/C++ CI + +on: + push: + paths: + bubble.cpp + bubble.h + test_bubble.cpp + pull_request: + paths: + bubble.cpp + bubble.h + test_bubble.cpp + +jobs: + Run_cpp: + + runs-on: ubuntu-latest + + steps: + - name: Checkout Code + uses: actions/checkout@v3 + + - name: Setup Compiler + run: sudo apt-get install g++ + + - name: Compile and Run Tests + run: | + g++ bubble.cpp test_bubble.cpp -o program + ./program + - name: Report Test Status + run: | + if [[ $? -eq 0 ]]; then + echo "Tests passed." + else + echo "Tests failed." + exit 1 + fi diff --git a/app.py b/app.py new file mode 100644 index 0000000..863293a --- /dev/null +++ b/app.py @@ -0,0 +1,33 @@ +from flask import Flask +from flask import request +from flask import json +from gitQueue import addData + +import redis +from rq import Queue + +q = Queue(connection=redis.Redis()) + +app = Flask(__name__) + + +@app.route('/') +def home(): + return 'Hello 🙂' + + +@app.route('/githubdata', methods=['POST']) +def apiMessage(): + + if request.headers['Content-Type'] == 'application/json': + job = q.enqueue(addData, json.dumps(request.json)) + + return json.dumps(request.json) + + return "error" + + +if __name__ == '__main__': + app.run(debug=True) + + diff --git a/bubble.h b/bubble.h new file mode 100644 index 0000000..a47cbb0 --- /dev/null +++ b/bubble.h @@ -0,0 +1,8 @@ +// bubble.h +#ifndef BUBBLE_H +#define BUBBLE_H + +// Declare the bubbleSort function +void bubbleSort(int arr[], int n); + +#endif diff --git a/challenge.py b/challenge.py new file mode 100644 index 0000000..b1e6222 --- /dev/null +++ b/challenge.py @@ -0,0 +1,19 @@ +import json + +def Pull_req(): + return 10 + +def Round2(round): + if round == 21: + return 10 + + elif round == 22: + #analyse the sorting algo + return 10 + return 0 + +def Round3(round): + if round == 31: + return 10 + return 0 + \ No newline at end of file diff --git a/dbms.py b/dbms.py new file mode 100644 index 0000000..4a32b59 --- /dev/null +++ b/dbms.py @@ -0,0 +1,28 @@ +import redis +from redis.commands.json.path import Path +import json + +r = redis.Redis() + +def updateUserScore(username,round,score): + + if round ==11: + points = 10 + elif round==21: + points = 20 + elif round==22 and score!=0: + points = 30 + elif round==31: + points = 40 + + if round != 11: + data = json.loads(r.get(username)) #deserializes into json format converts into dict + data['score'] = points + data['round'] = round + r.set(username,json.dumps(data)) #converts dict to json and updates the database + + # else: + + return 'success' + + diff --git a/gitQueue.py b/gitQueue.py new file mode 100644 index 0000000..832d3af --- /dev/null +++ b/gitQueue.py @@ -0,0 +1,34 @@ +import json +from rounds import * +from challenge import * +from dbms import updateUserScore + +def addData(request): + request=json.loads(request) + username=request['sender']['login'] + round=Rounds(request) + + status = 'none' + + if round == 11: + score = Pull_req() + status = updateUserScore(username, round, score) + return status + + elif round == 21: + score = Round2(round) + status = updateUserScore(username, round, score) + return status + + elif round == 22: + score = Round2(round) + status = updateUserScore(username, round, score) + return status + + elif round == 21: + score = Round2(round) + status = updateUserScore(username, round, score) + return status + + return status + diff --git a/rounds.py b/rounds.py new file mode 100644 index 0000000..7b819e1 --- /dev/null +++ b/rounds.py @@ -0,0 +1,39 @@ +from flask import Flask +import json,requests + +def riddle_ans(string): + + return str(string.split('-')[1]) + + + +def check_forked(username,repo): + url = f"https;//github.com/{username}/{repo}" #username = glugmvit, repo = yet to be created + response = requests.get(url) + + if response.status_code == 200: + data = response.json() + is_forked = data.get('fork', False) + return is_forked + print("error in check forked") + return False + + + +def Rounds(request): + + if 'forkee' in request.keys(): + return 11 + + elif 'issue' in request.keys(): + riddle_answer=[] + if riddle_ans(str(request['comment']['body'])) in riddle_answer: + return 21 + else: + return 22 #pending {analyse the algo} + + elif check_forked('glugmvit','repo'): + return 31 + + + diff --git a/send_req.py b/send_req.py new file mode 100644 index 0000000..4d43015 --- /dev/null +++ b/send_req.py @@ -0,0 +1,6 @@ +import requests + +url = 'http://127.0.0.1:5000/githubdata' + +r = requests.post(url) +print(r.content) \ No newline at end of file diff --git a/test_bubble.cpp b/test_bubble.cpp new file mode 100644 index 0000000..5c962d6 --- /dev/null +++ b/test_bubble.cpp @@ -0,0 +1,28 @@ +// test_bubble.cpp +#include +#include "bubble.h" + +int main() { + int arr[] = {5, 2, 8, 12, 3}; + int n = sizeof(arr) / sizeof(arr[0]); + + // Call your bubble sort function + bubbleSort(arr, n); + + // Verify the sorted array + bool sorted = true; + for (int i = 1; i < n; ++i) { + if (arr[i] < arr[i - 1]) { + sorted = false; + break; + } + } + + if (sorted) { + std::cout << "Test passed: Array is sorted." << std::endl; + return 0; + } else { + std::cerr << "Test failed: Array is not sorted." << std::endl; + return 1; + } +}