GitHub GraphQL: Get all forks of specific repository - github

I would like to get a list of all the forks of a specific repository.
When I try the following on explorer
repository( owner: "someOrg", name: "specificRepo"){
name
forkCount
forks(first: 12){
totalCount
nodes{
name
}
}
}
}
It returns the fork count correctly, but inside nodes, the name is just the original repo name. But I would like it to give the names of all the forked repositories.
{
"data": {
"repository": {
"name": "specificRepo",
"forkCount": 12,
"forks": {
"totalCount": 1,
"nodes": [
{
"name": "specificRepo",
}
]
}
}
}
}

If you fork a repo and then change the name, the name field will reflect the changed name, not the original name. For example, here's a fork of Semantic-UI:
{
repository(
owner: "Semantic-Org"
name: "Semantic-Ui"
) {
name
forkCount
forks(
first: 12
orderBy: { field: NAME, direction: DESC }
) {
totalCount
nodes {
name
}
}
}
}
{
"data": {
"repository": {
"name": "Semantic-UI",
"forkCount": 4936,
"forks": {
"totalCount": 4743,
"nodes": [
{
"name": "WEB_JS_GUI-Semantic-UI"
},
{
"name": "Vanz-Sing-In"
},
{
"name": "Somewhat-Semantic-UI"
},
{
"name": "semantic_1.0_experiment"
},
{
"name": "semanticui"
},
{
"name": "semantic.ui_main"
},
{
"name": "Semantic-UI-V2"
},
{
"name": "Semantic-UI-tr"
},
{
"name": "Semantic-UI-tr"
},
{
"name": "Semantic-UI-Stylus"
},
{
"name": "Semantic-UI-pt-br"
},
{
"name": "Semantic-UI-pp"
}
]
}
}
}
}

Today you can request to add the nameWithOwner field as well and even the url. That will give you the information you need.
{
repository(
owner: "Semantic-Org"
name: "Semantic-Ui"
) {
name
forkCount
forks(
first: 12
orderBy: { field: NAME, direction: DESC }
) {
totalCount
nodes {
name
nameWithOwner
url
}
}
}
}
Which will give you:
{
"data": {
"repository": {
"name": "Semantic-UI",
"forkCount": 5133,
"forks": {
"totalCount": 4919,
"nodes": [
{
"name": "Vanz-Sing-In",
"nameWithOwner": "semantic-apps/Vanz-Sing-In",
"url": "https://github.com/semantic-apps/Vanz-Sing-In"
},
etc.
}
}
}
}

Related

Cannot find # in OpenSearch query

I have an index that includes a field and when a '#' is input, I cannot get the query to find the #.
Field Data: "#3213939"
Query:
GET /invoices/_search
{
"query": {
"bool": {
"should": [
{
"match": {
"referenceNumber": {
"query": "#32"
}
}
},
{
"wildcard": {
"referenceNumber": {
"value": "*#32*"
}
}
}
]
}
}
}
"#" character drops during standard text analyzer this is why you can't find it.
POST _analyze
{
"text": ["#3213939"]
}
Response:
{
"tokens": [
{
"token": "3213939",
"start_offset": 1,
"end_offset": 8,
"type": "<NUM>",
"position": 0
}
]
}
You can update the analyzer and customize it.
https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-standard-analyzer.html
OR
you can use referenceNumber.keyword field.
GET test_invoices/_search
{
"query": {
"bool": {
"should": [
{
"match": {
"referenceNumber": {
"query": "#32"
}
}
},
{
"wildcard": {
"referenceNumber.keyword": {
"value": "*#32*"
}
}
}
]
}
}
}

mongodb, Updating a field in an object in array field equal to a document field

let's say I have docs such as
{
"nickname": "my nickname",
"comments": [
{
"id": 1
},
{
"id": 1
}
]
}
how do I update it to look like
{
"nickname": "my nickname",
"comments": [
{
"id": 1,
"nickname": "my nickname"
},
{
"id": 1,
"nickname": "my nickname"
}
]
}
This does not seem to be working
db.getCollection('users').update(
{
"comments.nickname": null
},
{ "$set": { "comments.$.nickname": "$nickname" } });
This is just an example to represent my problem.
I would not like to hear about re-structuring and optimizing the fields.
Thanks!
Try this (v4.2):
db.users.updateMany(
{"comments.nickname":null},
[
{"$set": {"comments.nickname": "$nickname"}}
]
)
Note: It will override if any comments.nickname already exists
db.users.aggregate([
{
$match: {
"comments.nickname": null
}
},
{
$addFields: {
comments: {
$map: {
input: "$comments",
in: {
id: "$$this.id",
nickname: {
$cond: [
"$$this.nickname",
"$$this.nickname",
"$nickname"
]
}
}
}
}
}
},
{
$out: "users"
}
])
Note: It will keep already existing values

Why does MapReduce return _id and value parameters?

I need to make a map reduce function which will search for a certain set of conditions within a document and then if they are met, return the entire document (or make a new table with the documents which match). The following is a simplified example of what i need to do but keep in mind that the actual documents have more to them.
Lets say i have two documents:
Document #1:
{
"_id": ObjectId("542ec1a91d40cafd58b928b4"),
"billing": {
"category1": {
"0": {
"mode": "email",
"email": {
"0": "test#what.com"
}
}
},
"category2": {
"0": {
"mode": "email",
"email": {
"0": "who#cares.net"
}
}
}
}
}
Document #2:
{
"_id": ObjectId("542ec1a91d40cafd58b928b4"),
"billing": {
"category1": {
"0": {
"mode": "email",
"email": {
"0": "test#what.com"
}
}
},
"category2": {
"0": {
"mode": "email"
}
}
}
}
I need to determine which documents have elements with a mode value of "email" but do not have a corresponding email element. This is what i've got so far:
var mapFunction = function() {
for(var bKey in this.billing) {
for (var bSubKey in this.billing[bKey]) {
var modeIsEmail = (this.billing[bKey][bSubKey].mode == 'email');
var emailElementIsMissing = (typeof this.billing[bKey][bSubKey].email == 'undefined');
if (modeIsEmail && emailElementIsMissing) {
var newDoc = this;
delete newDoc._id;
emit('document', newDoc);
}
}
}
}
var reduceFunction = function(documentKey, badRecord) {
return badRecord;
}
db.cust.mapReduce(mapFunction, reduceFunction, { out:"test_reduce"})
While this technically works I am annoyed and confused by the structure of the output. This is what the output looks like:
"_id" : "document",
"value" : {
"billing": {
"category1": {
"0": {
"mode": "email",
"email": {
"0": "test#what.com"
}
}
},
"category2": {
"0": {
"mode": "email",
"email": {
"0": "who#cares.net"
}
}
}
}
}
Why is my resulting structure not exactly the same as the original documents? What i need is to get rid of the "_id" and "value" elements at the root and return this:
{
"_id": ObjectId("542ec1a91d40cafd58b928b4"),
"billing": {
"category1": {
"0": {
"mode": "email",
"email": {
"0": "test#what.com"
}
}
},
"category2": {
"0": {
"mode": "email"
}
}
}
}
How can this be done?

filter range date elasticsearch

This is how my datas look like
{
"name": "thename",
"openingTimes": {
"monday": [
{
"start": "10:00",
"end": "14:00"
},
{
"start": "19:00",
"end": "02:30"
}
]
}
}
I want to query this document saying, opened on monday between 13:00 and 14:00.
I tried this filter but it doesn't return my document:
{
"filter": {
"range": {
"openingTimes.monday.start": {
"lte": "13:00"
},
"openingTimes.monday.end": {
"gte": "14:00"
}
}
}
}
If I simply say opened on monday at 13:00, it works:
{
"filter": {
"range": {
"openingTimes.monday.start": {
"lte": "13:00"
}
}
}
}
Or even closing on monday from 14:00, works too:
{
"filter": {
"range": {
"openingTimes.monday.start": {
"gte": "14:00"
}
}
}
}
but combining both of them doens't give me anything. How can I manage to create a filter meaning opened on monday between 13:00 and 14:00 ?
EDIT
This is how I mapped the openingTime field
{
"properties": {
"monday": {
"type": "nested",
"properties": {
"start": {"type": "date","format": "hour_minute"},
"end": {"type": "date","format": "hour_minute"}
}
}
}
}
SOLUTION (#DanTuffery)
Based on #DanTuffery answer I changed my filter to his (which is working perfectly) and added the type definition of my openingTime attribute.
For the record I am using elasticsearch as my primary db through Ruby-on-Rails using the following gems:
gem 'elasticsearch-rails', git: 'git://github.com/elasticsearch/elasticsearch-rails.git'
gem 'elasticsearch-model', git: 'git://github.com/elasticsearch/elasticsearch-rails.git'
gem 'elasticsearch-persistence', git: 'git://github.com/elasticsearch/elasticsearch-rails.git', require: 'elasticsearch/persistence/model'
Here is how my openingTime attribute's mapping looks like:
attribute :openingTimes, Hash, mapping: {
type: :object,
properties: {
monday: {
type: :nested,
properties: {
start:{type: :date, format: 'hour_minute'},
end: {type: :date, format: 'hour_minute'}
}
},
tuesday: {
type: :nested,
properties: {
start:{type: :date, format: 'hour_minute'},
end: {type: :date, format: 'hour_minute'}
}
},
...
...
}
}
And here is how I implemented his filter:
def self.openedBetween startTime, endTime, day
self.search filter: {
nested: {
path: "openingTimes.#{day}",
filter: {
bool: {
must: [
{range: {"openingTimes.#{day}.start"=> {lte: startTime}}},
{range: {"openingTimes.#{day}.end" => {gte: endTime}}}
]
}
}
}
}
end
First create your mapping with the openingTimes object at the top level.
/PUT http://localhost:9200/demo/test/_mapping
{
"test": {
"properties": {
"openingTimes": {
"type": "object",
"properties": {
"monday": {
"type": "nested",
"properties": {
"start": {
"type": "date",
"format": "hour_minute"
},
"end": {
"type": "date",
"format": "hour_minute"
}
}
}
}
}
}
}
}
Index your document
/POST http://localhost:9200/demo/test/1
{
"name": "thename",
"openingTimes": {
"monday": [
{
"start": "10:00",
"end": "14:00"
},
{
"start": "19:00",
"end": "02:30"
}
]
}
}
With a nested filter query you can search for the document with the start and end fields within boolean range queries:
/POST http://localhost:9200/demo/test/_search
{
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"nested": {
"path": "openingTimes.monday",
"filter": {
"bool": {
"must": [
{
"range": {
"openingTimes.monday.start": {
"lte": "13:00"
}
}
},
{
"range": {
"openingTimes.monday.end": {
"gte": "14:00"
}
}
}
]
}
}
}
}
}
}
}

Find in subdocuments returning document

I have a collection looking somewhat like this:
{
"colors": ["blue","white"],
"items": {
"old": {
"name": "test"
}
"current": {
"name": "new_test"
}
}
},
{
"colors": ["red","green"],
"items": {
"old": {
"name": "test2"
}
"current": {
"name": "new_test2"
}
}
},
Is it possible to use find like this:
db.collection.find({"items": { "old": { "name": "test" } } })
So the command would return:
{
"colors": ["blue","white"],
"items": {
"old": {
"name": "test"
}
"current": {
"name": "new_test"
}
}
}
Is this possible?
Yes, you can use the 'dot notation' to reach into the object:
db.collection.find({"items.old.name": "test" })
The query syntax you used also works, but it has different semantics: It will match the entire subdocument for equality instead of just a single field. For instance, the following query would also return a result:
db.foo.find({"items.old": {"name" : "test"} }),
butdb.collection.find({"items": { "old": { "name": "test" } } }) does not, because items also contains a current field.