jenkins-bot has submitted this change and it was merged.

Change subject: remove hardcoded properties
......................................................................


remove hardcoded properties

Change-Id: I65fc7f71627bfdba61ef1aa1ac0225de8fd308c7
Signed-off-by: Loic Dachary <l...@dachary.org>
---
M FLOSSbot/qa.py
M FLOSSbot/repository.py
2 files changed, 36 insertions(+), 29 deletions(-)

Approvals:
  Dachary: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/FLOSSbot/qa.py b/FLOSSbot/qa.py
index d893c6c..deb58a4 100644
--- a/FLOSSbot/qa.py
+++ b/FLOSSbot/qa.py
@@ -58,11 +58,14 @@
 
     def run(self):
         QUERY = """
-        SELECT DISTINCT ?item WHERE {
-            ?item wdt:P1324 ?repo FILTER CONTAINS(str(?repo), "github.com").
-            FILTER NOT EXISTS { ?item p:P2992 ?qa }
-        }
-        """
+        SELECT DISTINCT ?item WHERE {{
+            ?item wdt:{source_code_repository}
+               ?repo FILTER CONTAINS(str(?repo), "github.com").
+            FILTER NOT EXISTS {{ ?item p:{software_quality_assurance} ?qa }}
+        }}
+        """.format(
+            source_code_repository=self.P_source_code_repository,
+            software_quality_assurance=self.P_software_quality_assurance)
         for item in pg.WikidataSPARQLPageGenerator(QUERY,
                                                    site=self.site,
                                                    result_type=list):
@@ -73,7 +76,8 @@
         item_dict = item.get()
         clm_dict = item_dict["claims"]
         headers = {'User-Agent': 'FLOSSbot'}
-        for url in [claim.getTarget() for claim in clm_dict['P1324']]:
+        for url in [claim.getTarget() for claim in
+                    clm_dict[self.P_source_code_repository]]:
             if 'github.com' not in url:
                 continue
             path = os.path.normpath(urlparse(url).path)[1:]
diff --git a/FLOSSbot/repository.py b/FLOSSbot/repository.py
index 9cedd79..49ad37d 100644
--- a/FLOSSbot/repository.py
+++ b/FLOSSbot/repository.py
@@ -179,31 +179,34 @@
     def run_query(self):
         if self.args.filter == 'no-protocol':
             query = """
-            SELECT DISTINCT ?item WHERE {
-              ?item p:P1324 ?repo.
-              ?repo ps:P1324 ?value.
-              OPTIONAL { ?repo pq:P2700 ?protocol } # try to get the protocol
+            SELECT DISTINCT ?item WHERE {{
+              ?item p:{source_code_repository} ?repo.
+              ?repo ps:{source_code_repository} ?value.
+              OPTIONAL {{ ?repo pq:{protocol} ?protocol }} # get the protocol
               FILTER(!BOUND(?protocol)) # and only keep those with no protocol
-            } ORDER BY ?item
-            """
+            }} ORDER BY ?item
+            """.format(source_code_repository=self.P_source_code_repository,
+                       protocol=self.P_protocol)
         elif self.args.filter == 'no-preferred':
             query = """
             SELECT ?item (COUNT(?value) AS ?count) WHERE
-            {
-              ?item p:P1324 [
-                 ps:P1324 ?value; wikibase:rank wikibase:NormalRank ].
-              MINUS { ?item p:P1324/wikibase:rank wikibase:PreferredRank. }
-            }
+            {{
+              ?item p:{source_code_repository} [
+                 ps:{source_code_repository} ?value;
+                 wikibase:rank wikibase:NormalRank ].
+              MINUS {{ ?item p:{source_code_repository}/wikibase:rank
+                       wikibase:PreferredRank. }}
+            }}
             GROUP BY ?item
             HAVING(?count > 1)
             ORDER BY ?item
-            """
+            """.format(source_code_repository=self.P_source_code_repository)
         else:
             query = """
-            SELECT DISTINCT ?item WHERE {
-              ?item wdt:P1324 ?url.
-            } ORDER BY ?item
-            """
+            SELECT DISTINCT ?item WHERE {{
+              ?item wdt:{source_code_repository} ?url.
+            }} ORDER BY ?item
+            """.format(source_code_repository=self.P_source_code_repository)
         query = query + " # " + str(time.time())
         log.debug(query)
         for item in pg.WikidataSPARQLPageGenerator(query,
@@ -219,15 +222,15 @@
         item_dict = item.get()
         clm_dict = item_dict["claims"]
 
-        if len(clm_dict['P1324']) == 1:
+        if len(clm_dict[self.P_source_code_repository]) == 1:
             return False
 
-        if len(clm_dict['P1324']) != 2:
+        if len(clm_dict[self.P_source_code_repository]) != 2:
             self.debug(item, "SKIP more than two URLs is too difficult to fix")
             return False
 
         http = []
-        for claim in clm_dict['P1324']:
+        for claim in clm_dict[self.P_source_code_repository]:
             if claim.getRank() == 'preferred':
                 self.debug(item,
                            "SKIP because there already is a preferred URL")
@@ -251,10 +254,10 @@
         clm_dict = item_dict["claims"]
 
         urls = []
-        for claim in clm_dict['P1324']:
+        for claim in clm_dict[self.P_source_code_repository]:
             urls.append(claim.getTarget())
 
-        for claim in clm_dict['P1324']:
+        for claim in clm_dict[self.P_source_code_repository]:
             url = claim.getTarget()
             extracted = self.extract_repository(url)
             if extracted and extracted not in urls:
@@ -273,10 +276,10 @@
                         claim.changeRank('preferred')
                     self.info(item, "PREFERRED set to " + url)
 
-        for claim in clm_dict['P1324']:
+        for claim in clm_dict[self.P_source_code_repository]:
             self.fixup_url(claim)
 
-        for claim in clm_dict['P1324']:
+        for claim in clm_dict[self.P_source_code_repository]:
             if self.P_protocol in claim.qualifiers:
                 self.debug(item, "IGNORE " + claim.getTarget() +
                            " because it already has a protocol")

-- 
To view, visit https://gerrit.wikimedia.org/r/311351
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I65fc7f71627bfdba61ef1aa1ac0225de8fd308c7
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/bots/FLOSSbot
Gerrit-Branch: master
Gerrit-Owner: Dachary <l...@dachary.org>
Gerrit-Reviewer: Dachary <l...@dachary.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to