sckott / cchecksapi

CRAN checks API (DEFUNCT)
https://github.com/r-hub/cchecksbadges
MIT License
33 stars 1 forks source link

Could/should the API prevent me from creating the same rule several times? #64

Closed maelle closed 4 years ago

maelle commented 4 years ago

Whilst working on docs I created the same rule several times. Should the submitted rule be compared to existing rules, and not created when it exists? Or is it a bad idea to have such a special behaviour?

maelle commented 4 years ago

Related to that, why not returning the rule ID in the data?

This way if it exists, the rule isn't created anew, its existing ID is returned.

maelle commented 4 years ago

what I mean by having created the same rule several times:

I ran

curl -XPOST -H "Authorization: Bearer ***" --data '[{"package": "natserv", "regex": "install failure"}]' \
 https://cranchecks.info/notifications/rules | jq .

a few times and now here are my rules...

email <- Sys.getenv("CCHECKS_EMAIL")
token <- Sys.getenv("CCHECKS_TOKEN")
cchecks::cchn_register(email = email, token = token)
#> Token added for 'msmaellesalmon@gmail.com'
cchecks::cchn_rule_list(email = email)
#> $error
#> NULL
#> 
#> $data
#>     id package rule_status rule_time rule_platforms      rule_regex
#> 1  119 natserv          NA        NA             NA install failure
#> 2  120 natserv          NA        NA             NA install failure
#> 3  121 natserv          NA        NA             NA install failure
#> 4  122 natserv          NA        NA             NA install failure
#> 5  123 natserv          NA        NA             NA install failure
#> 6  124 natserv          NA        NA             NA install failure
#> 7  125 natserv          NA        NA             NA install failure
#> 8  126 natserv          NA        NA             NA install failure
#> 9  127 natserv          NA        NA             NA install failure
#> 10 128 natserv          NA        NA             NA install failure
#> 11 129 natserv          NA        NA             NA install failure
#> 12 130 natserv          NA        NA             NA install failure
#> 13 131 natserv          NA        NA             NA install failure

Created on 2020-05-16 by the reprex package (v0.3.0)

sckott commented 4 years ago

yeah, probably shouldn't allow the same rule to be created if it exists. - use internal method rules_find to find rules matching criteria given, if match, return id , maybe return message that rule existed already?

maelle commented 4 years ago

that'd be great!

sckott commented 4 years ago

probably will return:

id and "created" message on success, and id and "rule already exists" message when matching rule found

[
  {
    "id": 1,
    "message": "created"
  },
  {
    "id": 2,
    "message": "rule already exists"
  }
]
maelle commented 4 years ago

Awesome! I'd write "rule already existed" (past tense)

maelle commented 4 years ago

this is really neat, thank you!