devopshq / artifactory

dohq-artifactory: a Python client for Artifactory
https://devopshq.github.io/artifactory/
MIT License
273 stars 139 forks source link

Artifactory Query Language get the latest artifact in a path #78

Closed chris-alation closed 5 years ago

chris-alation commented 5 years ago

How would one sort and limit results when using the library? Basically, get the latest artifact in path.

Using the API I see that one can do something like this: .sort({"$desc" : ["created"]}).limit(1) with find.

But how to include this when using the library? I'm not sure how to include the sort and limit in the below code.

aql = ArtifactoryPath("https://myartifactory.com/artifactory", auth=('username','password'))

args = ["items.find", {"$and": [
        { "repo": {"$eq": "myrepo"} },
        {
            "$or": [
                {"path": {"$match": "path/in/repo"}}
            ]
        }
        ]
}]

artifacts_list = aql.aql(*args)
allburov commented 5 years ago

@chris-alation how did you solve this?

sushant-pradhan commented 5 years ago

@chris-alation Can you update how you managed to solve this?

Kirlocca commented 4 years ago

Since OP doesn't answer, here is the solution:

aql = ArtifactoryPath("https://myartifactory.com/artifactory", auth=('username','password'))

args = ["items.find", {"$and": [
        { "repo": {"$eq": "myrepo"} },
        {
            "$or": [
                {"path": {"$match": "path/in/repo"}}
            ]
        }
        ]
},
".sort", {"$desc" : ["created"]},
".limit", [1]
]
artifacts_list = aql.aql(*args)