Skip to content

Commit

Permalink
added yml file for pipeline and restructured files and folders2
Browse files Browse the repository at this point in the history
  • Loading branch information
arsalan-dev-engineer committed Jul 29, 2024
1 parent be51039 commit 9cfbd03
Show file tree
Hide file tree
Showing 13 changed files with 257 additions and 483 deletions.
146 changes: 146 additions & 0 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
---
name: Project Pipeline

# Defining events that trigger workflow
on:
pull_request:
# Trigger on pull requests to any branch
branches:
- "*"
types:
- opened
- edited
- reopened
- synchronize

push:
branches:
# Trigger on pushes to the main branch
- main

# Set top-level permissions
permissions:
# Read access to repository contents
contents: read
# Read access to packages (e.g., npm packages)
packages: read

# Define the workflow jobs
jobs:
# Initial Checkout and Setup
checkout-and-setup:
name: "1. Checkout and Setup"
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
# Fetch entire history of the repository
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
# Use Node.js version 14.x
node-version: "14.x"
# Cache npm dependencies for faster builds
cache: "npm"
- name: Install Dependencies
# Install project dependencies using npm
run: npm install

# Run Security Scan
security-scan:
name: "2. Run Security Scan"
needs: checkout-and-setup
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
# Fetch entire history of the repository
fetch-depth: 0
- name: Run Security Scanner
uses: gitleaks/gitleaks-action@v2
env:
# Gitleaks scans for sensitive data in the codebase
GITHUB_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }}

# Run Code Lint
code-lint:
name: "3. Run Code Lint"
needs: security-scan
runs-on: ubuntu-latest
permissions:
contents: read
packages: read
statuses: write
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
# Fetch the entire history of the repository
fetch-depth: 0
- name: Run Code Linter
uses: super-linter/super-linter@v6.6.0
env:
# Super-linter checks code for stylistic and syntactical errors
GITHUB_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }}

# Check Dependencies
check-dependencies:
name: "4. Check Dependencies"
needs: code-lint
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
# Use Node.js version 14.x
node-version: "14.x"
- name: Install Clean Dependencies
# Install dependencies based on package-lock.json for consistency
run: npm ci
- name: Run Outdated Check
# Check for outdated dependencies to ensure they are up-to-date
uses: odanado/outdated-check-action@v0

# Generate Changelog
generate-changelog:
name: "5. Generate Changelog"
runs-on: ubuntu-latest
needs: check-dependencies
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
# Fetch the entire history of the repository
fetch-depth: 0
- name: Generate Changelog
# Generate a changelog based on commit history for project documentation
run: |
git log --pretty=format:"* %h - %an, %ar : %s" > CHANGELOG.md
cat CHANGELOG.md # Output the changelog
update-readme-with-terraform-docs:
name: "6. Generate tf module docs"
# Runs on Ubuntu environment
runs-on: ubuntu-latest
needs: generate-changelog
steps:
# Fetches code from the pull request
- uses: actions/checkout@v4

- name: Generate Terraform module docs and update README.md
# Uses a tool to generate docs
uses: terraform-docs/gh-actions@v1.2.0
with:
# Works in the main repository folder
working-dir: .
# Updates the README with docs
output-file: README.md
# Inserts docs into README
output-method: inject
env:
token: ${{ secrets.REPO_ACCESS_TOKEN }}
138 changes: 0 additions & 138 deletions projects/to_do_list_api/client.py

This file was deleted.

103 changes: 103 additions & 0 deletions projects/todo_api/client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import requests

# Base URL for the API endpoints
# This is the address where the server is listening for requests.
base_url = "http://127.0.0.1:8000/todolist/"

def create_list(list_data):
"""
Send a POST request to create a batch of to-do lists.
"""
response = requests.post(base_url, json=list_data)
return response.json()

def get_all_lists():
"""
Send a GET request to retrieve all to-do lists.
"""
response = requests.get(base_url)
return response.json()

def get_list(lst_id):
"""
Send a GET request to retrieve a specific to-do list by ID.
"""
response = requests.get(f"{base_url}{lst_id}")
return response.json()

def update_to_do_list(lst_id, list_data):
"""
Send a PUT request to update a specific to-do list by ID.
"""
response = requests.put(f"{base_url}{lst_id}", json=list_data)
return response.json()

def delete_to_do_list(lst_id):
"""
Send a DELETE request to remove a specific to-do list by ID.
"""
response = requests.delete(f"{base_url}{lst_id}")
return response.json()

# Example data for testing
example_list_data = [
{
"id": "1",
"title": "Task 1",
"description": "Description for Task 1",
"due_date": "2024-07-24",
"status": "pending",
"priority": "medium",
"creation_date": "2024-07-23"
}
]

# Test API functions
# The following lines of code test the functions to ensure they are working as expected.

print("Creating list...")
# Calls the function to create a new to-do item and prints the response from the server.
print(create_list(example_list_data))

print("Getting all lists...")
print(get_all_lists())

print("Getting list with ID 1...")
print(get_list("1"))

# Make a copy of the first item in the example list
# This creates a duplicate of the to-do item so we can make changes without altering the original data.
updated_list_data = example_list_data[0].copy()

# Update the title of the copied to-do item
# This changes the title of the copied item to "Updated Task 1".
updated_list_data["title"] = "Updated Task 1"

print("Updating list...")
print(update_to_do_list("1", updated_list_data))

print("Deleting list...")
print(delete_to_do_list("1"))

print("Getting all lists after deletion...")
print(get_all_lists())


"""
# Test POST request
curl -X POST http://127.0.0.1:8000/todolist/ \
-H "Content-Type: application/json" \
-d '[{
"id": "1",
"title": "Task 1",
"description": "Description for Task 1",
"due_date": "2024-07-24",
"status": "pending",
"priority": "medium",
"creation_date": "2024-07-23"
}]'
# Test GET request
curl -X GET http://127.0.0.1:8000/todolist/ \
-H "Content-Type: application/json"
"""
Loading

0 comments on commit 9cfbd03

Please sign in to comment.