Page 1 of 1

How to search bugs or create a bug in Mantis Bug Tracker using python?

Posted: 07 Nov 2023, 00:48
by nzacharakis
I have a small Python script that logs in to my company's Mantis Bug Tracking system. I surfed around for ways to search based on the Summary field or create a new Mantis bug, but nothing helped me so far. Can someone please steer me to the correct direction?

FYI The log-in code I tried is the following

Code: Select all

import argparse
import re
import logging
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
from datetime import datetime, timedelta


logging.basicConfig(level=logging.INFO)

def mantisLogin(baseURL, fsa_user, fsa_pwd):
    options = webdriver.ChromeOptions()
    options.add_argument('--headless')
    options.add_argument('--no-sandbox')
    options.add_argument('--disable-gpu')

    driver = webdriver.Chrome(options=options)
    driver.get(baseURL)
    WebDriverWait(driver, 5).until(EC.url_contains("login"))
    username = driver.find_element("id", "id_username")
    password = driver.find_element("id", "id_password")
    username.clear()
    password.clear()
    username.send_keys(fsa_user)
    password.send_keys(fsa_pwd)
    driver.find_element(By.CLASS_NAME, "submit").click()
    WebDriverWait(driver, 5).until(EC.url_contains("main_page.php"))

    return driver

def main(args):
    credentials_file = "credentials.txt"
    try:
        username = args.username
        password = args.password
    except Exception as e:
        print(f"Failed to read credentials: {e}")
        return

    mantisURL = "http://mantis-dev.*********.com/"

    try:
        driver = mantisLogin(mantisURL, username, password)
    except Exception as e:
        print(f"Failed to login: {e}")
        return
    
    print(str(driver))
    driver.quit()

if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument("username")
    parser.add_argument("password")
    main(parser.parse_args())
Thank you

Re: How to search bugs or create a bug in Mantis Bug Tracker using python?

Posted: 07 Nov 2023, 12:23
by atrol
It's better to use the MantisBT REST API Instead of trying to automate a browser.
https://www.mantisbt.org/docs/master/en ... p/#restapi

Re: How to search bugs or create a bug in Mantis Bug Tracker using python?

Posted: 07 Nov 2023, 18:52
by nzacharakis
@atrol
Thank you for your reply. I went through the documentation on the site you sent me but unfortunately I could not find anything specific to my problem. Are there any additional docs that show how to use MantisBT with Python for specific actions, like search or find or create etc.? Thank you

Re: How to search bugs or create a bug in Mantis Bug Tracker using python?

Posted: 07 Nov 2023, 19:13
by atrol
REST APIs are a common standard and are not language specific.
I recommend to visit a Python forum If you need support on writing a client application that consumes a REST API.
Not sure, but I don't expect that someone will provide support for this in the MantisBT forum.

I searched a bit and found this tutorial that might help you to start https://realpython.com/api-integration-in-python/

Re: How to search bugs or create a bug in Mantis Bug Tracker using python?

Posted: 07 Nov 2023, 19:17
by atrol
Just found that you can even change the language on the API description, so you have examples in Python
https://documenter.getpostman.com/view/ ... b999274e95

Re: How to search bugs or create a bug in Mantis Bug Tracker using python?

Posted: 07 Nov 2023, 19:51
by nzacharakis
@atrol
Thank you very much for the valuable information and your effort to help! I will look into them right away. :D