Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need a more customizable way of getting the config file #34

Closed
le-doude opened this issue Jan 19, 2015 · 7 comments
Closed

Need a more customizable way of getting the config file #34

le-doude opened this issue Jan 19, 2015 · 7 comments

Comments

@le-doude
Copy link

To sync all our config files for various setups for our devs we use services that require some form of authentication.
For example:
We sometime use private github repos to get a file hosted on a "config" repo. We can get those files with

curl -u <some_oauth_token>:x-basic-oauth https://raw.githubusercontent/[user/org]/[reponame]/[branch]/[path_tyo_file]

It would be nice to have something that allows for more complex requests by setting headers. Or defining our own process.

@matthewfarwell
Copy link
Member

I'm reluctant to start adding authentication to the scalastyle plugin. Apart from it being a lot of new options (username/password, basic/digest, should we ignore certificate problems, etc. etc.), I don't think it fits. You can always make the scalastyle task dependent upon another task - this would probably give you what you need.

@le-doude
Copy link
Author

That is what I am doing

lazy val updateScalaStyle = taskKey[Unit]("updateScalaStyle")

lazy val refreshConfFile: Long = 24 * 60 * 60 * 1000

updateScalaStyle := {
  val conf = file("scalastyle-config.xml")
  if (!conf.exists() || (new Date().getTime - conf.lastModified()) > refreshConfFile){
    val oauthToken = "<MYTOKEN>"
    val configFileUrl = "https://raw.githubusercontent.com/user/repo/branch/path/scalastyle-config.xml"
    val result: Int = s"curl -u $oauthToken:x-oauth-basic $configFileUrl -O" !
  }else{
    println("No need to update")
  }
}

(scalastyle in Compile) <<= (scalastyle in Compile) dependsOn updateScalaStyle

(scalastyle in Test) <<= (scalastyle in Test) dependsOn updateScalaStyle

I plan on adding a call to the github api to check if it has been updated instead of the 24 hours expiry. But the gist of it is here.

@matthewfarwell
Copy link
Member

Could you perhaps raise a PR to add this to the docs? If not, I will do it

https://github.com/scalastyle/scalastyle.github.com/blob/master/sbt.markdown

@2rs2ts
Copy link

2rs2ts commented Jan 21, 2015

@le-doude Are you using personal access tokens for your solution? It'd be nice to have something that "just works" with enterprise github too.

@le-doude
Copy link
Author

@2rs2ts
Here is the final version I am using to get file from a github private repo. It works fine and the speed is quite fast in the scalastyle conf case. I tried comparing sha using github API v3 but it was slower (it became 2 calls on update needed) or same speed (when non need to update) at most so I just update the file every single time.
BTW I .gitignore the file so that everybody in the project is up to date all the time on the scalastyle rules.

https://gist.github.com/8d17f8355138bea4d7a5.git

@matthewfarwell sure

@2rs2ts
Copy link

2rs2ts commented Jan 22, 2015

@le-doude Using .gitignore works but if you use the current download option the file gets downloaded to target/scalastyle-config.xml and the plugin uses that file instead. When you go to issue a PR for this feature you can have the plugin continue to take advantage of that. Then you will also be able to use the scalastyleConfigRefreshHours setting, which I admit isn't as nice as using the github API, but it will work for non-github users!

@matthewfarwell
Copy link
Member

Tidying the issues list, closing this issue. If this is still a problem, please reopen or raise another issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants