<commit_before>;;; Copyright 2012 <NAME> All Rights Reserved.
;;;
;;; Licensed under the Apache License, Version 2.0 (the "License");
;;; you may not use this file except in compliance with the License.
;;; You may obtain a copy of the License at
;;;
;;;     http://www.apache.org/licenses/LICENSE-2.0
;;;
;;; Unless required by applicable law or agreed to in writing, software
;;; distributed under the License is distributed on an "AS IS" BASIS,
;;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
;;; See the License for the specific language governing permissions and
;;; limitations under the License.

(in-package #:orcabot)

(defmodule bugzilla bugzilla-module ("bug")
  (cookies :reader cookies-of :initform (make-instance 'drakma:cookie-jar))
  (base-url :accessor base-url-of))

(defun bugzilla-login (module)
  (let ((creds (authentication-credentials (puri:uri-host (puri:uri (base-url-of module))))))
    (drakma:http-request (format nil "~a/index.cgi" (base-url-of module))
                         :method :post
                         :parameters `(("Bugzilla_login" . ,(getf creds :login))
                                       ("Bugzilla_password" . ,(getf creds :password)))
                         :cookie-jar (cookies-of module))))

(defun retrieve-bug-info (module bug)
  (unless (drakma:cookie-jar-cookies (cookies-of module))
    (bugzilla-login module))
  (multiple-value-bind (response status headers)
      (drakma:http-request
       (format nil "~a/show_bug.cgi?ctype=xml&id=~a" (base-url-of module) bug)
       :cookie-jar (cookies-of module))
    (cond
      ((/= status 200)
       nil)
      ((and (string= (cdr (assoc :content-type headers))
                     "text/html; charset=UTF-8")
            (cl-ppcre:scan "need a legitimate login and password" response))
       (bugzilla-login module)
       (retrieve-bug-info module bug))
      (t
       (flet ((resolver (pubid sysid)
                (declare (ignore pubid))
                (when (puri:uri= sysid
                                 (puri:parse-uri
                                  (format nil "~a/bugzilla.dtd" (base-url-of module))))
                  (open "data/bugzilla.dtd" :element-type '(unsigned-byte 8)))))
         (let* ((doc (cxml:parse response
                                 (cxml-dom:make-dom-builder)
                                 :entity-resolver #'resolver))
                (bug (elt (dom:get-elements-by-tag-name doc "bug") 0))
                (err (dom:get-attribute-node bug "error")))
           (unless err
             (values
              (dom:node-value
               (dom:first-child
                (elt (dom:get-elements-by-tag-name doc "short_desc") 0)))
              (dom:node-value
               (dom:first-child
                (elt (dom:get-elements-by-tag-name doc "assigned_to") 0)))
              (dom:node-value
               (dom:first-child
                (elt (dom:get-elements-by-tag-name doc "bug_status") 0)))))))))))<commit_msg>Correct path is now computed for bugzilla DTD<commit_after>;;; Copyright 2012 <NAME> All Rights Reserved.
;;;
;;; Licensed under the Apache License, Version 2.0 (the "License");
;;; you may not use this file except in compliance with the License.
;;; You may obtain a copy of the License at
;;;
;;;     http://www.apache.org/licenses/LICENSE-2.0
;;;
;;; Unless required by applicable law or agreed to in writing, software
;;; distributed under the License is distributed on an "AS IS" BASIS,
;;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
;;; See the License for the specific language governing permissions and
;;; limitations under the License.

(in-package #:orcabot)

(defmodule bugzilla bugzilla-module ("bug")
  (cookies :reader cookies-of :initform (make-instance 'drakma:cookie-jar))
  (base-url :accessor base-url-of))

(defun bugzilla-login (module)
  (let ((creds (authentication-credentials (puri:uri-host (puri:uri (base-url-of module))))))
    (drakma:http-request (format nil "~a/index.cgi" (base-url-of module))
                         :method :post
                         :parameters `(("Bugzilla_login" . ,(getf creds :login))
                                       ("Bugzilla_password" . ,(getf creds :password)))
                         :cookie-jar (cookies-of module))))

(defun retrieve-bug-info (module bug)
  (unless (drakma:cookie-jar-cookies (cookies-of module))
    (bugzilla-login module))
  (multiple-value-bind (response status headers)
      (drakma:http-request
       (format nil "~a/show_bug.cgi?ctype=xml&id=~a" (base-url-of module) bug)
       :cookie-jar (cookies-of module))
    (cond
      ((/= status 200)
       nil)
      ((and (string= (cdr (assoc :content-type headers))
                     "text/html; charset=UTF-8")
            (cl-ppcre:scan "need a legitimate login and password" response))
       (bugzilla-login module)
       (retrieve-bug-info module bug))
      (t
       (flet ((resolver (pubid sysid)
                (declare (ignore pubid))
                (when (puri:uri= sysid
                                 (puri:parse-uri
                                  (format nil "~a/bugzilla.dtd" (base-url-of module))))
                  (open (orcabot-path "data/bugzilla.dtd") :element-type '(unsigned-byte 8)))))
         (let* ((doc (cxml:parse response
                                 (cxml-dom:make-dom-builder)
                                 :entity-resolver #'resolver))
                (bug (elt (dom:get-elements-by-tag-name doc "bug") 0))
                (err (dom:get-attribute-node bug "error")))
           (unless err
             (values
              (dom:node-value
               (dom:first-child
                (elt (dom:get-elements-by-tag-name doc "short_desc") 0)))
              (dom:node-value
               (dom:first-child
                (elt (dom:get-elements-by-tag-name doc "assigned_to") 0)))
              (dom:node-value
               (dom:first-child
                (elt (dom:get-elements-by-tag-name doc "bug_status") 0)))))))))))
{'fraction_non_alphanumeric': 0.13448559670781893, 'fraction_numerical': 0.005596707818930041, 'mean_word_length': 2.0936863543788187, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4965279', 'n_tokens_mistral': 1867, 'n_tokens_neox': 1763, 'n_words': 491}