Skip to content

Commit

Permalink
feat: Added args for whitelist and CICD 💗 (#8)
Browse files Browse the repository at this point in the history
* Swapped to Poetry

* fix: finished swapping to Poetry

* dev: Updated GH Actions

* docs(changelog): update release notes

* wip: Added test n suite stuff

* feat: Added white list logic and unit tests and CICD YOLO

* Fix poetry lock

* Swapped to simple make file, cause everyone has it and it's good enough heh heh

* Added missing CICD

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
Jelloeater and github-actions[bot] authored Dec 11, 2023
1 parent f53e87e commit 1c61cdd
Show file tree
Hide file tree
Showing 27 changed files with 1,606 additions and 174 deletions.
16 changes: 16 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# http://editorconfig.org/#file-format-details
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[Makefile]
indent_style = tab
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "pip" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
21 changes: 21 additions & 0 deletions .github/workflows/Run-TODO-to-Issue.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: "Run TODO to Issue"
on: ["push"]
jobs:
build:
runs-on: "ubuntu-latest"
steps:
- uses: "actions/checkout@v3"
- name: "TODO to Issue"
uses: "alstr/todo-to-issue-action@v4"
with:
AUTO_ASSIGN: true
#No issues have been created
#
# Make sure your file language is in syntax.json.
# The action will not recognise existing TODOs that have already been pushed, unless you run the action manually.
# If a similar TO DO appears in the diff as both an addition and deletion, it is assumed to have been moved, so is ignored.
# If your workflow is executed but no issue is generated, check your repo permissions by navigating to Settings -> Actions (General) -> Workflow permissions and enable "Read and write permissions".
#
#Multiple issues have been created
#
#Issues are created whenever the action runs and finds a newly added TO DO in the diff. Rebasing may cause a TO DO to show up in a diff multiple times. This is an acknowledged issue, but you may have some luck by adjusting your workflow file.
76 changes: 76 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"

on:
push:
branches: [ "main" ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ "main" ]
schedule:
- cron: '17 8 * * 5'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'python' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Use only 'java' to analyze code written in Java, Kotlin or both
# Use only 'javascript' to analyze code written in JavaScript, TypeScript or both
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support

steps:
- name: Checkout repository
uses: actions/checkout@v3

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality


# Autobuild attempts to build any compiled languages (C/C++, C#, Go, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun

# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.

# - run: |
# echo "Run, Build Application using script"
# ./location_of_script_within_repo/buildscript.sh

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
category: "/language:${{matrix.language}}"
File renamed without changes.
21 changes: 21 additions & 0 deletions .github/workflows/release_gen.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Release

on:
push:
tags:
- "v[0-9]+.[0-9]+.[0-9]+"

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v3
- uses: BobAnkh/[email protected]
with:
ACCESS_TOKEN: ${{secrets.GITHUB_TOKEN}}
- uses: ncipollo/release-action@v1
with:
allowUpdates: true
generateReleaseNotes: true
22 changes: 22 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Test

on:
pull_request: { }
push:
branches: [ main ]
tags: [ "*" ]
# workflow_dispatch:
jobs:
test:
runs-on: "ubuntu-latest"
steps:
- uses: actions/checkout@v2
- run: tree
- run: make setup
- uses: nick-fields/retry@v2
with:
timeout_minutes: 5
max_attempts: 3
retry_on: error
command: make

50 changes: 2 additions & 48 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,49 +1,3 @@
# Changelog
# CHANGELOG

## [v0.2.0](https://github.com/db0/pythonseer/tree/v0.2.0) (2023-09-13)

[Full Changelog](https://github.com/db0/pythonseer/compare/v0.1.3...v0.2.0)

**Merged pull requests:**

- feat: Hesitations [\#5](https://github.com/db0/pythonseer/pull/5) ([db0](https://github.com/db0))

## [v0.1.3](https://github.com/db0/pythonseer/tree/v0.1.3) (2023-09-08)

[Full Changelog](https://github.com/db0/pythonseer/compare/v0.1.2...v0.1.3)

**Merged pull requests:**

- doc: update [\#4](https://github.com/db0/pythonseer/pull/4) ([db0](https://github.com/db0))

## [v0.1.2](https://github.com/db0/pythonseer/tree/v0.1.2) (2023-08-09)

[Full Changelog](https://github.com/db0/pythonseer/compare/v0.1.1...v0.1.2)

**Merged pull requests:**

- fix: package name [\#3](https://github.com/db0/pythonseer/pull/3) ([db0](https://github.com/db0))

## [v0.1.1](https://github.com/db0/pythonseer/tree/v0.1.1) (2023-08-09)

[Full Changelog](https://github.com/db0/pythonseer/compare/v0.1.0...v0.1.1)

**Merged pull requests:**

- Fix lemmy publish [\#2](https://github.com/db0/pythonseer/pull/2) ([db0](https://github.com/db0))

## [v0.1.0](https://github.com/db0/pythonseer/tree/v0.1.0) (2023-08-09)

[Full Changelog](https://github.com/db0/pythonseer/compare/0.0.1...v0.1.0)

## [0.0.1](https://github.com/db0/pythonseer/tree/0.0.1) (2023-08-09)

[Full Changelog](https://github.com/db0/pythonseer/compare/41d38f11b23fe5f15caf0078e50a175cbcfecb07...0.0.1)

**Merged pull requests:**

- First release on pypi [\#1](https://github.com/db0/pythonseer/pull/1) ([db0](https://github.com/db0))



\* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)*
\* *This CHANGELOG was automatically generated by [auto-generate-changelog](https://github.com/BobAnkh/auto-generate-changelog)*
21 changes: 21 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
BUILD_DIR=pythonseer

all:
rm -rf dist
poetry cache clear _default_cache --all --no-interaction
poetry cache clear PyPI --all --no-interaction
poetry check
poetry run whispers $(BUILD_DIR) # Check for security issues
poetry run tartufo scan-local-repo .
poetry run vulture --min-confidence 100 $(BUILD_DIR)
poetry run ruff format $(BUILD_DIR)
poetry run pytest --cov --cov-fail-under=50

setup:
python3 -m pip install pipx
python3 -m pipx ensurepath
pipx install poetry
poetry install

install:
pip install . --upgrade
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,10 @@ A Python package to interact with [Fediseer](https://fediseer.com)
# Examples

See working examples in [examples/](https://github.com/db0/pythonseer/tree/main/examples)

# Testing

```shell
make setup
make
```
37 changes: 25 additions & 12 deletions examples/censures.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,45 @@

## python examples/censures.py db0

import os
import argparse
import os

from pythonseer import Fediseer
from pythonseer.types import FormatType


arg_parser = argparse.ArgumentParser()
arg_parser.add_argument('-d', '--fediverse_domain', action='store', required=False, type=str, help="the fediverse instance domain for which to look up censures")
arg_parser.add_argument('-m', '--min_censures', action='store', required=False, default=1, type=int, help="The min amount of censures to require for each instance")
arg_parser.add_argument('-r', '--reasons', action='store', required=False, type=str, help="A csv of reasons with which to filter intances")
arg_parser.add_argument(
"-d",
"--fediverse_domain",
action="store",
required=False,
type=str,
help="the fediverse instance domain for which to look up censures",
)
arg_parser.add_argument(
"-m",
"--min_censures",
action="store",
required=False,
default=1,
type=int,
help="The min amount of censures to require for each instance",
)
arg_parser.add_argument(
"-r", "--reasons", action="store", required=False, type=str, help="A csv of reasons with which to filter intances"
)
args = arg_parser.parse_args()



fediverse_domain = args.fediverse_domain
if not fediverse_domain:
fediverse_domain = os.getenv('FEDIVERSE_DOMAIN', "lemmy.dbzer0.com,lemmings.world,lemmy.world")
fediverse_domain = os.getenv("FEDIVERSE_DOMAIN", "lemmy.dbzer0.com,lemmings.world,lemmy.world")
if not fediverse_domain:
raise Exception("You need to provide a fediverse domain via env var or arg")

fediseer = Fediseer()
censures = fediseer.censure.get_given(
domain_set=fediverse_domain,
reasons=args.reasons,
min_censures=args.min_censures,
format=FormatType.CSV)
domain_set=fediverse_domain, reasons=args.reasons, min_censures=args.min_censures, format=FormatType.CSV
)
if censures:
print(f"{fediverse_domain} has censured the following instances: {censures['csv']}")
else:
Expand Down
17 changes: 11 additions & 6 deletions examples/endorsements.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@

## python examples/endorsements.py db0

import os
import argparse
import os

from pythonseer import Fediseer
from pythonseer.types import FormatType


arg_parser = argparse.ArgumentParser()
arg_parser.add_argument('-d', '--fediverse_domain', action='store', required=False, type=str, help="the fediverse instance domain for which to look up endorsements")
arg_parser.add_argument(
"-d",
"--fediverse_domain",
action="store",
required=False,
type=str,
help="the fediverse instance domain for which to look up endorsements",
)
args = arg_parser.parse_args()



fediverse_domain = args.fediverse_domain
if not fediverse_domain:
fediverse_domain = os.getenv('FEDIVERSE_DOMAIN', "lemmy.dbzer0.com")
fediverse_domain = os.getenv("FEDIVERSE_DOMAIN", "lemmy.dbzer0.com")
if not fediverse_domain:
raise Exception("You need to provide a fediverse domain via env var or arg")

Expand Down
Loading

0 comments on commit 1c61cdd

Please sign in to comment.