Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions .github/workflows/detect-ai.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Runs script to detect the likelihood of a PR have being create
# by an agent, or with a human with heavy use of AI.

name: Detect AI

on:
pull_request:
branches:
- master
- uncover-agent

permissions:
contents: read
pull-requests: write
issues: write

jobs:
analyse:
name: Classify PR (AI vs human)
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CODEBERG_TOKEN: ${{ secrets.CODEBERG_TOKEN }}
steps:
- name: Check out repository
# The Codeberg repo is private, so we have to clone it with a Codeberg token
run: |
set -euo pipefail
[ -n "$CODEBERG_TOKEN" ] || { echo "::error::CODEBERG_TOKEN secret is required"; exit 1; }
clone_url="https://user:${CODEBERG_TOKEN}@codeberg.org/geoamish/uncover-agent.git"
git clone --quiet "$clone_url" "$RUNNER_TEMP/uncover-agent"
shopt -s dotglob
mv "$RUNNER_TEMP/uncover-agent"/* .
rmdir "$RUNNER_TEMP/uncover-agent"

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12" # we can change this later

- name: Run uncover_agents.py
run: |
set -euo pipefail
PR_URL="https://github.com/${{ github.repository }}/pull/${{ github.event.pull_request.number }}"
python uncover_agents.py "$PR_URL" | tee result.json

- name: Apply AI / human label
run: |
set -euo pipefail
LABEL=$(python3 -c "import json;print(json.load(open('result.json')).get('label',''))")
echo "Classifier label: $LABEL"
case "$LABEL" in
Low)
gh pr edit "$PR_NUMBER" --repo "${{ github.repository }}" --add-label "human generated" ;;
High|Very\ High)
gh pr edit "$PR_NUMBER" --repo "${{ github.repository }}" --add-label "AI generated" ;;
*)
echo "Label '$LABEL' maps to no auto-label; nothing to do." ;;
esac
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
3 changes: 3 additions & 0 deletions .uncover-agent/NOTE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# uncover-agent test diff
# original: https://github.com/geopython/pygeoapi/pull/1080
# generated 2026-10-19 16:15:29 UTC
75 changes: 75 additions & 0 deletions .uncover-agent/added.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# ****************************** -*-
# flake8: noqa
# =================================================================
#
# Authors: Francesco Bartoli <xbartolone@gmail.com>
#
# Copyright (c) 2022 Francesco Bartoli
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
# files (the "Software"), to deal in the Software without
# restriction, including without limitation the rights to use,
# copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following
# conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
#
# =================================================================

from enum import Enum

from pydantic import BaseModel


class SupportedFormats(Enum):
JSON = "json"
YAML = "yaml"


class OAPIFormat(BaseModel):
__root__: SupportedFormats = SupportedFormats.YAML
# Authors: Francesco Bartoli <xbartolone@gmail.com>
# Copyright (c) 2022 Francesco Bartoli
import io
from pathlib import Path
from typing import Union
from pygeoapi.models.openapi import OAPIFormat
def generate_openapi_document(cfg_file: Union[Path, io.TextIOWrapper],
output_format: OAPIFormat):
"""
Generate an OpenAPI document from the configuration file

:param cfg_file: configuration Path instance
:param output_format: output format for OpenAPI document

:returns: content of the OpenAPI document in the output
format requested
"""
if isinstance(cfg_file, Path):
with cfg_file.open(mode="r") as cf:
s = yaml_load(cf)
else:
s = yaml_load(cfg_file)
pretty_print = s['server'].get('pretty_print', False)

if output_format == 'yaml':
content = yaml.safe_dump(get_oas(s), default_flow_style=False)
else:
content = to_json(get_oas(s), pretty=pretty_print)
return content


content = generate_openapi_document(config_file, format_)
Loading